Java Loops MCQs with answers
69 questions tagged Java Loops, each with the correct answer and an explanation. Page 1 of 4.
- Which of these is NOT necessary in a for loop?
- Which is not a loop type in Java?
- What is the output? for (int i = 0; i <= 2; i++) { for (int j = 0; j <= 1; j++) { System.out.print(i + j); } }
- What is the result? for (int i = 0; i < 1; i--)
- Which of the following can replace the update part in a for loop? for (int i = 0; i < 5; ?)
- What is the purpose of the update expression in a for loop?
- Which loop condition will cause the loop to terminate immediately? while(?)
- What happens when break is executed in a nested loop?
- Which of the following is true about labeled loops in Java?
- What is the effect of an empty loop body?
- How many times will this loop execute? for (int i = 0; i < 10; i += 3)
- What happens when a continue statement is used inside a loop?
- Which loop is most readable for running a counter from 1 to 10?
- Which is the correct syntax of a for-each loop?
- Which type of loop should be used when the number of iterations is not known beforehand?
- What is printed by this loop? int i = 0; while (i < 3) { System.out.print(i); i++; }
- What does the following code print? for (int i = 5; i > 0; i--) { System.out.print(i); }
- Which condition will make this loop run forever? while(?)
- Which of the following loops is best for traversing elements in a collection?
- What will be the output? for (int i = 1; i <= 5; i++) { if (i % 2 == 0) continue; System.out.print(i); }