1Z0-811 Control Flow and Loops Practice Question
A programmer wants to iterate over a list of strings and print each that starts with 'A'. Which loop construct is best suited?
⚠ Common exam trap
The 1Z0-811 exam often tests the misconception that a traditional for loop with an index is always the most flexible or efficient choice, but for simple element access without index manipulation, the enhanced for loop is the idiomatic and recommended construct in Java.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Enhanced for loop
The enhanced for loop (for-each) is best suited because it provides a clean, concise syntax for iterating over a collection like a List<String> without needing an explicit index or iterator. It directly yields each element, allowing a simple if-statement to check if the string starts with 'A' and print it, making the code more readable and less error-prone.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Do-while loop
Why it's wrong here
Not appropriate because you don't need to guarantee one iteration.
- ✓
Enhanced for loop
Why this is correct
Simplest for iterating over all elements.
- ✗
Traditional for loop with index
Why it's wrong here
Works but more error-prone.
- ✗
While loop with iterator
Why it's wrong here
Requires extra handling.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.