MCQ Single Best Answer Moderate

QHow does a for-each loop differ from a traditional for loop?

ID: #23078 For Loop in Programming Language 80 views
Question Info
#23078Q ID
ModerateDifficulty
For Loop in Programming LanguageTopic

Choose the Best Option

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

  • A It requires a counter
  • B It works only with arrays
  • C It iterates over a collection without an index
  • D It can modify the loop control variable
Correct Answer: Option C

Explanation

A for-each loop (or enhanced for loop) is specifically used to iterate over elements in a collection or array, but it does so without requiring an explicit index or counter. The for-each loop automatically handles the iteration through the elements, simplifying the syntax and making the code more readable. It does not allow for modifying the loop control variable directly, which distinguishes it from traditional for loops.

Share This Question

Challenge a friend or share with your study group.