What does continue do inside a loop?
break leaves the loop entirely.
Control Flow Statements · Exercise 1 of 4
Twenty multiple-choice questions on Java control flow: if-else, classic switch and fall-through, switch expressions and yield, pattern matching switch, while, do-while, for, break, continue and labels. Pick an option to check your answer instantly.
What does continue do inside a loop?
break leaves the loop entirely.
In nested loops, what does break outer; do, where outer labels the outer loop?
continue outer would move to the next iteration of the outer loop.
for (int x : arr) x = 0; – what happens to arr?
Use an index loop to assign elements.
How many times does for (int i = 2; i <= 20; i += 4) run?
i = 2, 6, 10, 14, 18.
Which loop header runs forever (until break or return)?
for (;;) and while (true) are both idiomatic. while (1) does not compile in Java.
What does if (x > 0); { System.out.println("positive"); } do?
A classic bug; IDEs warn about empty statements.
Without braces, in if (a) if (b) x(); else y();, which if does the else belong to?
An else binds to the nearest unmatched if – the "dangling else". Braces make intent explicit.
What does javac do with a statement written directly after return; in the same block?
Unreachable statements are compile errors in Java.
When is a switch usually clearer than an if-else ladder?
Range checks still need if (or guards in a pattern switch).
Why must case Integer i when i > 0 come before case Integer i?
javac reports "this case label is dominated by a preceding case label".
Timed online tests with instant scores and explanations.