Test 5 Flashcards
1
Q
While loop benefits
A
- Must REPEAT until certain condition met
- Apply to numerous situations
- If condition FALSE at the beginning, loop is NEVER EXECUTED
2
Q
While loop format
A
int ctr=1; while (ctr { System out print (ctr); ctr++; }
3
Q
Do-while benefits
A
- ALWAYS EXECUTES body of loop at least once
- Exit-condition
- Good if ur asking a question who’s answer determines if the loop is repeated
4
Q
Do-while format
A
int ctr=1; do { System.out.println(ctr); ctr++; } while (ctr
5
Q
For loop
A
Repeated a specific #of times
Allows u to input # of repetitions
6
Q
For loop format
A
int ctr=1;
for(ctr=1; ctr
7
Q
Each pass through a loop is called an
A
Iteration
8
Q
In a group of nested loops, which loop is executed the least #of times?
A
Outer
9
Q
Nested loops
A
Outer loop changes after inner loop is completely finished
10
Q
for (rows=0;rows
A
AAAA AAAA AAAA AAAA AAAA
11
Q
Nested for loop with output:
N
NN
A
The inner would be
for (col=0; col
12
Q
What’s wrong? int x=4; while(x>1) x++;
A
The loop is an infinite
Fix: int x=1; while(x