Junior — Middle
Can you explain how the while loop works in Dart?
sobes.tech AI
Answer from AI
The while loop in Dart executes a block of code as long as the condition is true. First, the condition is checked, and if it is true, the loop body is executed. Then, the condition is checked again, and this process repeats until the condition becomes false.
Example:
int count = 0;
while (count < 5) {
print('Count: $count');
count++;
}
In this example, the loop will print values from 0 to 4. Once count reaches 5, the condition count < 5 becomes false, and the loop ends.