Entry-Controlled while vs Exit-Controlled do-while
Understanding when code is guaranteed to run at least once
| Loop Type | Condition Evaluated | Min Iterations | Primary Use Case |
|---|---|---|---|
while (condition) { ... } | Before loop body (Entry-controlled) | 0 times | Stream processing, reading till EOF |
do { ... } while (condition); | After loop body (Exit-controlled) | 1 time (guaranteed) | User input menus, password retries |