Week 4

Ch. 5 Loops

- While Loop
- Counter Variables
- Sentinel Values
- Running Total
- Input Validation
- Do While Loop
- Menu Based Programs with loop and validation
- For Loop
- Nested Loops
- Variable Scope
- Infinite Loop
- Off By One

Increment and Decrement Op
++ and -- are operators that add and subtract 1 from their operands.

num = num + 1;
num += 1;
num++;      // postfix
++num;      // prefix

num = num - 1;
num -= 1;
num--;      // postfix
--num;      // prefix

While Loop

A loop is a block of code that repeats:
- while loop: pre-test
- do while loop: post-test
- for loop: pre-test

While loop syntax:

while( expression ) {
  // body
  // of
  // loop
}

Do While loop syntax:

do {
  // body
  // of
  // loop
}while( expression );

For Loop syntax:

for( init; expression; update  ) {
  // body
  // of
  // loop
}