Module 3 (Prelim) Flashcards
3.1 Overview 3.2 Loop Structure 3.3 while Loop 3.4 Increment and Decrement Operators 3.5 for Loop 3.6 do...while Loop 3.7 Nested Loops 3.8 break and continue Statements
A structure that allows repeated execution of a block of statements
Loop
A block of statements that are executed repeatedly
Loop body
One execution of any loop
Iteration
Three types of loops
while
for
do…while
The loop-controlling Boolean expression is the first statement
while
A concise format in which to execute loops
for
The loop-controlling Boolean expression is the last statement
do…while
Executes a body of statements continually. As long as the Boolean expression that controls entry into the loop continues to be true
while loop
while loop syntax:
while (expression)
….statement
Performs a task a predetermined number of times
Definite loop or counter-controlled loop
Definite loop or counter-controlled loop is also called _________
counted loop
Sentinel variable is tested in the condition. Loop ends when sentinel is encountered
Indefinite or Sentinel-controlled while loops
A loop that never ends. Can result from a mistake in the while loop
Infinite loop
Suspect an infinite loop when:
-The same output is displayed repeatedly
-The screen remains idle for an extended period of time
To exit an infinite loop:
- press and hold Ctrl + C
- Break
is an operator used for one value
unary operators
- The result is calculated and stored
- Then the variable is used
Prefix ++
- The variable is used
- Then the result is calculated and stored
Postfix ++
Prefix and postfix increment operators
++someValue and someValue++
Prefix and postfix decrement operators
–someValue and someValue–
The expression (x++) simply means______
A) add 1 to x and return the old value (Postfix increment)
B) add 1 to x and return the new value (Prefix increment)
C) take 1 from x and return the old value (Postfix decrement)
D) take 1 from x and return the new value (Prefix decrement)
A) add 1 to x and return the old value
The expression (++x) simply means______
A) add 1 to x and return the old value (Postfix increment)
B) add 1 to x and return the new value (Prefix increment)
C) take 1 from x and return the old value (Postfix decrement)
D) take 1 from x and return the new value (Prefix decrement)
B) add 1 to x and return the new value
The expression (–x) simply means______
A) add 1 to x and return the old value (Postfix increment)
B) add 1 to x and return the new value (Prefix increment)
C) take 1 from x and return the old value (Postfix decrement)
D) take 1 from x and return the new value (Prefix decrement)
D) take 1 from x and return the new value
The expression (x–) simply means______
A) add 1 to x and return the old value (Postfix increment)
B) add 1 to x and return the new value (Prefix increment)
C) take 1 from x and return the old value (Postfix decrement)
D) take 1 from x and return the new value (Prefix decrement)
C) take 1 from x and return the old value