Loops Flashcards

1
Q

What does a while loop do?

A

While loop loops through a block of code as long as a specified condition is true.

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

What’s a do/while loop?

A

It’s a variant of the while loop which executes a block of code once, before checking it the condition is true, theh it repeats the loop as long as its true.

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

For loop?

A

They are used when you know exactly how many times you want to loop through a block of code.

for (stat1; stat2; stat3) 〔
// code to run

Stat1 is executed on e before the execution of the code block in brackets.

Stat2 defines the condition for executing the block.(which is why you may be using the for loop in the first place, since you know this to be relatively exact)

Stat3 is executed every time after the code block has been executed.

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

Nested Loops?

A

It’s placing a lopp inside of another loop. UNDERSTAND!??!

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

For each loop?

A

It’s used exclusively to loop through elements in an array.

for (type variableName : arrayName) 〔
//code to be executed

String[] cars = 〔”Volvo”, “BMW”, “Ford”, “MAZDA”〕;
for (String i : cars) 〔
System.out.println(i);

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

What does a continue statement do?

A

It skips an iteration

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