EECS 183 Lecture Notes - Lecture 9: Infinite Loop, Data Validation, While Loop
1
EECS 183 Full Course Notes
Verified Note
1 document
Document Summary
Variable += expression is same as variable = variable + (expression) Ex: x += 5; is same as x = x + 5; When used in expressions cout << i++; cout << ++i; Loops cout << i; i = i+1 i = i + 1; cout << i; Loop is a block of code that is executed more than once in a row. Keeps executing as long as condition is true. Body of loop must change the condition so that it"s eventually false. If a semicolon after the condition, it"s an empty statement loop body. Used for executing block of code a specific number of times. Better to use for loop if you know how many times the loop would iterate. Used for executing a block of code until specified condition is false. Use while for event controlled where you don"t know how many times the loop will iterate often times when user enters input.