Concept Flow - Return inside loops
Start function
Enter loop
Check condition
Yes
Execute loop body
Return encountered?
Yes→Exit function immediately
No
Next iteration
Back to Check condition
Exit loop
Return at end of function
Function ends
↩Back to Check condition
The function starts and enters a loop. If a return statement is hit inside the loop, the function exits immediately. Otherwise, the loop continues until its condition fails, then the function returns at the end.