Loops Flashcards
What are the 2 advantages of Looping?
Understanding the Advantages of Looping
- Looping makes computer programming efficient and
worthwhile - Write one set of instructions to operate on multiple,
separate sets of data
Understanding the Advantages of Looping
What is a Loop in programming?
Understanding the Advantages of Looping
Loop: structure that repeats actions while some
condition continues
Understanding the Advantages of Looping
TRUE OR FALSE: As long as a Boolean expression remains true, a while loop’s body executes. It also controls the number of repetitions
Understanding the Advantages of Looping
TRUE
Understanding the Advantages of Looping
What type of variable fits this function?
* initialized before entering loop
* Loop control variable tested
* Body of loop must alter value of loop control variable
Using a Loop Control Variable
Loop control variable
Using a Loop Control Variable
What are the two ways that controls the repetition of a loop variable?
Using a Loop Control Variable
Repetitions are controlled by:
* Counter
* Sentinel value
Using a Loop Control Variable
What type of loop executes the predetermined number of times in a loop?
Definite loop
What type of loop program counts loop repetitions
Using a Definite Loop with a Counter
Counter-controlled loop
Using a Definite Loop with a Counter
Loop control variables altered by?
Using a Definite Loop with a Counter
Incrementing - adding
Decrementing - reducing
Using a Definite Loop with a Counter
What type of loop performs a different number of times each time the
program executes
Indefinite Loop
What are the 3 crucial steps in using an indefinite loop?
Using a Indefinite Loop with a Sentinel Value
Three crucial steps:
* Starting value to control the loop must be provided
* Comparison must be made using the value that controls
the loop
* Within the loop, value that controls the loop must be
altered
Using a Indefinite Loop with a Sentinel Value
What are the three steps that should occur in every properly functioning
loop?
Understanding the Loop in a Program’s
Mainline Logic
Three steps that should occur in every properly functioning
loop:
* Provide a starting value for the variable that will control
the loop
* Test the loop control variable to determine whether the
loop body executes
* Alter the loop control variable
Understanding the Loop in a Program’s
Mainline Logic
What is it called when there are loops between loops?
Nested Loops
Nested Loops
Nested Loops
What type of loop contains the other loop?
Nested Loops
Outer Loops
Nested Loops
What type of loop is contained?
Nested Loops
Inner Loops
Nested Loops
What type of loop is needed when values of two (or more) variables repeat to produce every combination of values?
Nested Loops
Nested Loops
Nested Loops