Difference between while loop & do while loop in Dart

Difference between while loop & do while loop in Dart

FeatureWhile LoopDo...While Loop
Loop EntryCondition is checked before entering the loopCode block is executed before checking the condition
Execution OrderCondition is evaluated before executionCode block is executed before condition check
GuaranteeMay execute zero times if condition is false initiallyExecutes at least once, then checks condition
Syntaxwhile (condition) { /* code */ }do { /* code */ } while (condition);
Usage ScenarioPreferable when the condition may be false initiallySuitable when at least one execution is required before condition check
Loop ContinuationContinues executing as long as the condition is trueContinues executing as long as the condition is true, but at least one execution is guaranteed
Exit ConditionCondition is checked before every iterationCondition is checked after every iteration

Example of While Loop:

void main() {
    var i = 1;
    while (i <= 5) {
        print(i);
        i++;
    }
}

Example Do While Loop:

void main() {
    var i = 1;
    do {
        print(i);
        i++;
    } while (i <= 5);
}