while loop is a control flow statement that repeatedly executes a block of code as long as a specified boolean condition evaluates to true. It is classified as an entry-controlled loop, meaning the condition is validated prior to the execution of the loop body.
Syntax
condition: An expression that must evaluate to abool.{ ... }: The block of code (loop body) executed if the condition is true.
Execution Logic
- Evaluation: The Dart runtime evaluates the expression inside the parentheses.
- Branching:
- If the condition is
true, the code inside the braces executes. - If the condition is
false, the loop terminates, and control passes to the statement immediately following the closing brace.
- If the condition is
- Iteration: After the loop body executes, control returns to step 1 to re-evaluate the condition.
Code Example
The following example demonstrates a standard iteration where a counter variable controls the loop termination.Infinite Loops
If the condition never evaluates tofalse, the loop will execute indefinitely, blocking the program’s main isolate unless externally interrupted.
Loop Control Statements
The execution flow within awhile loop can be modified using the break and continue keywords.
break: Immediately terminates the loop, bypassing the condition check and resuming execution after the loop body.continue: Skips the remainder of the current iteration and jumps immediately to the condition evaluation for the next iteration.
Master Dart with Deep Grasping Methodology!Learn More





