Java Loops MCQs with answers Page - 6

You will find multiple-choice questions (MCQs) related to #Java Loops here. Go through these questions to prepare effectively for your upcoming exams and interviews.

To view the correct answer for any question, simply click the "Show Answer" button.

Have a question to share? Click on "Add Question" to contribute!

A

Admin • 828.43K Points
Coach

Q. Which of the following loops is best for traversing elements in a collection?

  • (A) for
  • (B) while
  • (C) do-while
  • (D) for-each

A

Admin • 828.43K Points
Coach

Q. Which condition will make this loop run forever?
while(?)

  • (A) i > 0
  • (B) true
  • (C) i != 0
  • (D) false

A

Admin • 828.43K Points
Coach

Q. What does the following code print?
for (int i = 5; i > 0; i--) {
System.out.print(i);
}

  • (A) 54321
  • (B) 12345
  • (C) 5
  • (D) error

A

Admin • 828.43K Points
Coach

Q. What is printed by this loop?
int i = 0;
while (i < 3) {
System.out.print(i);
i++;
}

  • (A) 012
  • (B) 123
  • (C) 234
  • (D) 321

A

Admin • 828.43K Points
Coach

Q. Which type of loop should be used when the number of iterations is not known beforehand?

  • (A) for
  • (B) while
  • (C) do-while
  • (D) switch

A

Admin • 828.43K Points
Coach

Q. Which is the correct syntax of a for-each loop?

  • (A) for(int i: array)
  • (B) for i in array
  • (C) foreach(int i in array)
  • (D) for each(int i; array)

A

Admin • 828.43K Points
Coach

Q. Which loop is most readable for running a counter from 1 to 10?

  • (A) for
  • (B) while
  • (C) do-while
  • (D) for-each

A

Admin • 828.43K Points
Coach

Q. What happens when a continue statement is used inside a loop?

  • (A) Terminates the loop
  • (B) Skips the current iteration
  • (C) Exits the program
  • (D) Repeats the current iteration

A

Admin • 828.43K Points
Coach

Q. How many times will this loop execute?
for (int i = 0; i < 10; i += 3)

  • (A) 3
  • (B) 4
  • (C) 5
  • (D) Infinite

A

Admin • 828.43K Points
Coach

Q. What is the effect of an empty loop body?

  • (A) Throws exception
  • (B) Does nothing per iteration
  • (C) Causes infinite loop
  • (D) Is illegal
What's Tag

As you may know, questions are organized under broad categories. Each category can include various types of questions. For example, the "History" category might contain questions about the Revolt of 1857, Shivaji Maharaj, Ancient History, Buddhism, and more.

To further refine this organization, we've introduced tags, which act as sub-categories to group questions more specifically.

Verified users can add tags to any question. If you have any suggestions regarding this system, we'd love to hear from you. Contact Us

Learn More