Week 10 Flashcards
o The 3 structures used in structured programming (includes Java)
Sequence
Selection (decision)
Repetition (loop)
o The repetition structure allows for a ________ of statements to be repeated
Sequence
o An advantage of Repetition structures is that they reduce
The amount of coding required, and make it easier to maintain software
o Another name for a while loop
Pretest loop
- What is a Loop Control Variable?
o Part of the Boolean expression controlling the loop
o The statements inside of the loop change the ____ ______ ________ so that the loop will eventually stop repeating
Loop control variable
o 3 Towers of using a loop control variable 3 things are needed
1. Initialize the loop control variables before entering the loop
2. Provide a condition that controls the loop
3. Alter the loop control variable within the loop, so that eventually the condition becomes false
- Definite Loop and Indefinite Loop
o Definite: A loop that executes a pre-determined number of times (Ex. Counter loop control variable that goes up or down by 1)
o Indefinite: A loop controlled by user input
o A loop control variable within an indefinite loop is called
A Sentinel value
o Steps to applying a loop in an existing program
Identify parts of the program that repeat
Use a loop for the repetitions
Test boundary conditions that control the loop
o Loop mistakes:
Not following the 3 towers
Using the wrong comparison operator
Placing statements inside of the loop that belong outside
o For loop
Similar to a while loop, but the initialization, condition, and increment are all on the same line
How is a for loop diagramed?
- The exact same way as a while loop
o A do-while loop is also called
A post-test loop
o This loop performs all of the statements, then checks if it should repeat at the end
Do-while loop