1Z0-811 Control Flow and Loops Practice Question
Which loop best suits a scenario where the number of iterations is unknown and depends on user input?
⚠ Common exam trap
Watch out — candidates often choose the do-while loop thinking it is better for user input because it always runs at least once, but the question specifies the number of iterations is unknown, and the while loop is more appropriate when the loop may need to be skipped entirely based on initial input.
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
✓
while loop
The while loop is best when the number of iterations is unknown and depends on user input because it evaluates a boolean condition before each iteration, allowing the loop to continue as long as the condition remains true. This is ideal for scenarios like reading user input until a sentinel value is entered, where the exact number of iterations cannot be predetermined.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
for loop
Why it's wrong here
Best for known number of iterations.
- ✓
while loop
Why this is correct
Condition checked before each iteration, suitable for unknown iterations.
- ✗
for-each loop
Why it's wrong here
Used for iterating over collections/elements.
- ✗
do-while loop
Why it's wrong here
Executes at least once, may not be appropriate if zero iterations possible.
Go deeper
Related to this question
About these practice questions
This 1Z0-811 question is part of Courseiva's 481-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.