=====
CS 111 - Week 13 Lecture 1 - 2025-11-18
=====
=====
TODAY WE WILL:
=====
* announcements
* more about assignment statements
* intro to while statement
* prep for next class
=====
* Should be working on Homework 10!
* at least 1st attempts must be submitted by 11:59 pm
on Friday, November 21
********
* YES, there IS lab, with a lab exercise, on Friday, November 21!
********
=====
* if not yet done for Spring 2026 advising:
MEET WITH YOUR ADVISOR(S)!
* RE-CREATE your DARS plan!
* get ready to REGISTER for SPRING 2026 between November 10-21!
* CS and SE majors:
* in Spring 2026, you should take:
CS 112 - CS Foundations 2
Math 253 - Discrete Math
* You CAN take Math 101T - Trigonometry and Math 253 CONCURRENTLY
* You CAN ask to switch to another ENGL 103 section if it conflicts
with a major requirement such as CS 112 or Math 253 that you need
to stay on-track in your major!
=====
CS 111 STYLE RULE
=====
* ALWAYS somehow give a first value to a local variable
BEFORE you use it!
* C++'s language definition does not define what
is in a newly-declared but not yet set local variable;
what is there, in reality? depends on the C++ compiler,
and those differ...!
* you should consider a newly-declared, not-yet-set local
variable to be undefined, thus, until you somehow give it
a value
=====
a bit more about the assignment statement
=====
* left_hand_side = right_hand_side;
thing_can_set = expr_to_set_it_to;
semantics: FIRST evaluate the right_hand_side,
the expr_to_set_it_to;
THEN, make that the NEW value of the left_hand_side,
the thing_can_set
int num;
num = 100;
num = num + 1; // USE num's current value, compute 100 + 1,
// and the result is num's NEW value
=====
CS 111 STYLE RULE
=====
* except for certain special kinds of parameters,
it is considered POOR STYLE to CHANGE a *parameter*
within a function's body
* if tempted: declare a local variable,
SET it to have the parameter's value,
and change that local variable instead!
======
the while statement
======
* one of SEVERAL statements C++ provides for
imperative-style repetition
* the MOST basic imperative-style repetition statement
is the while statement
* syntax:
while (bool_expr)
statement;
...but remember a block is considered a single statement
by the C++ compiler, so MORE typically:
while (bool_expr)
{
statement1;
...
statementN;
}
* the statement/block after the while is often called
the while statement's/while loop's BODY
* semantics:
1. evaluate the bool_expr
2. IF it is true, do the loop's body statements
and go back to step 1
ELSE continue after the loop body
* NOTE that something in the while's body
NEEEEEEDS to eventually do SOMETHING --
CHANGE something --
to make sure that its bool_expr eventually becomes false!
* otherwise? you get an INFINITE loop
(it won't stop until YOU stop it,
something overflows, the operating system stops
it, something crashes, etc....!)
* frequently:
* the bool_expr will involve a local variable
* that local variable is changed in the loop body
* that change (or combination of changes) eventually
leads the bool_expr to be false
=====
SIDE NOTES: when your function has side-effects!
=====
* when your function has side-effects,
you are expected to describe them in your purpose statement
(also ADD a "has the side-effect(s)" part)
* when your function has side effects,
you are expected to describe them as best you can in
your tests (yes, this gets a bit kluge-y...!)
* and you need to add additional cout statement(s) to
describe those side-effects in a testing main function
as well
* for example: see today's example function cheer