MCQ Single Best Answer Moderate

Q1. What is the correct syntax for a for loop in Java?

ID: #23071 For Loop in Programming Language 91 views
Question Info
#23071Q ID
ModerateDifficulty
For Loop in Programming LanguageTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A for (i = 0, i < 10, i++)
  • B for (int i = 0; i < 10; i++)
  • C for (int i = 0: i < 10: i++)
  • D for i in range(10)
Correct Answer: Option B

Explanation

In Java, the correct syntax of a for loop includes three parts inside the parentheses, separated by semicolons. The first part is the initialization (int i = 0), the second part is the condition check (i < 10), and the third part is the increment (i++). The loop will continue executing until the condition becomes false. Option A is incorrect because commas are used instead of semicolons. Option C uses colons instead of semicolons, which is not valid in Java. Option D is the syntax for Python, not Java.

No Previous Next Question

Share This Question

Challenge a friend or share with your study group.