Loops Flashcards

Learn all about loops

1
Q

What two main categories of loops are there?

A

Pre-test and post-test.

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

Which loop constructs (in Java) exist for doing a post-test loop?

A
Do while loop.
do {
    // Do stuff.
} while(condition);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What loop constructs (in Java) exist to perform a pre-test loop?

A

The while and for loops.
while(condition) { }
for(initialize; condition; update) { }

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

What would be printed?
for(int i = 0; i < 9; i++) {
print(i + “, “);
}

A

“0, 1, 2, 3, 4, 5, 6, 7, 8, “

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
What are the values of the variables after the loop?
int x = 3, y = 0;
while(x % 5 != 0) {
   y += x++;
}
A
y = 7
x = 5
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the values of the variables after the loop?
int qq = 16;
while(qq > 3)
qq–;

A

qq = 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
What are the values of the variables after the loop?
int x = 5, y = 15;
while(x != y) {
    x++;
    y--;
}
A

x and y = 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
What are the values of the variables after the loop?
int x = 4, y = 15;
while(x != y) {
    x++;
    y--;
}
A

There is no after the loop. This loop will run infinitely.

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