Loops Flashcards

1
Q

What are the 3 major structures of flow of control?

A

Sequences, choice, and repetition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the while loop?

A

keep executing the code statements over and over, as long as the boolean expression evaluates true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the condition?

A

The boolean expression in a loop that determines whether a loop should continue or exit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is start/initialization code?

A

initialize variables that you will use to keep track of when to stop your loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is upkeep code?

A

changes the variables used in the condition so that the loop stops at some point

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are for loops?

A

loops that let you write count-controlled loops in a condensed form

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the formula for a for loop?

A

for (initialization; expression; upkeep) {body}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the order of execution for a for loop?

A
  • initialization: done only once
  • condition: checked before each loop through
  • upkeep: done at the end of each loop through
  • body: executed each time through the loop, if the condition is true
  • statements after loop: will be executed as soon as condition is false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What kind of variables can you use as the counter in your for loops?

A

Don’t use floating-point data types, as they are not exact.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the scope of the iterator variable in for loops?

A

The for loop and nothing else. That means you can use the same variable name in multiple loops that are not nested

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a do-while loop?

A

a “bottom-tested” while loop; runs code once before checking your condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can you choose which loop to use?

A

for loop: if you know exactly how many times the loop should iterate (don’t over use)
while loop: if you need the possibility of the loop not happening
do-while loop: if you need the loop to be done at least once

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are keywords that you can use to control the flow of a loop?

A

break: immediately terminates the loop it’s in
continue: immediately terminates the current iteration of the loop it’s in

How well did you know this?
1
Not at all
2
3
4
5
Perfectly