Compound Condition In A While Loop
Consider the following code segment.
public class ConditionLoop {
public static void main(String[] args) {
int a = 0;
while(a < 5 && a != 3) {
System.out.println(a);
a++;
}
}
}
All of the following statements about the while loop are true EXCEPT:
A
The && operator requires both conditions (a < 5 and a != 3) to be true for the loop to execute.
B
The loop executes only while both conditions are satisfied.
C
The loop prints numbers from 0 to 4, ignoring the fact that a is compared to 3 in the condition.
D
The loop stops when a equals 3 because the second condition (a != 3) becomes false.
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | y.seong2027 | 2 | 2 | 0m 28s | 172 |
| #2 | hitrishabhatia | 1 | 3 | 0m 00s | 80 |
| #3 | khanhnguyen.thor | 1 | 1 | 1m 34s | 6 |
Items per page:
10
1 – 3 of 3
APFIVE