do-while loop is an exit-controlled iteration statement that executes a block of code once before evaluating a boolean condition. Unlike the standard while loop, the do-while loop guarantees that the loop body runs at least one time, regardless of whether the condition is initially true or false.
Syntax
Parameters
- Statement(s): A block of code enclosed in braces
{}that performs the loop’s operations. - Condition: An expression that evaluates to a
bool. This is evaluated after the execution of the statement block.
Execution Logic
- Body Execution: The program enters the
doblock and executes the statements contained within it. - Condition Evaluation: Upon reaching the
whilekeyword, the specified condition is evaluated. - Branching:
- If the condition evaluates to
true, control returns to the beginning of thedoblock, and the process repeats. - If the condition evaluates to
false, the loop terminates, and control passes to the next statement following the loop.
- If the condition evaluates to
Example
The following example demonstrates the syntax and execution flow. Note that the variablecount is incremented inside the loop, eventually causing the condition count < 3 to evaluate to false.
False Condition Behavior
Because the condition is evaluated at the end of the iteration, the body executes once even if the condition isfalse at the start.
Loop Control Statements
Thedo-while loop supports standard Dart control flow statements:
break: Immediately terminates the loop, bypassing the condition check.continue: Skips the remainder of the current iteration and jumps directly to the condition evaluation at the end of the loop.
Master Dart with Deep Grasping Methodology!Learn More





