Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen while Loop in Dart | Loops in Dart
Introduction to Dart

bookwhile Loop in Dart

A while loop is a programming construct that allows you to execute a specific block of code as long as a certain condition is true.

The syntax for a while loop in Dart is as follows:

loop.dart

loop.dart

copy
123
while (condition) { // Statements to be executed while a condition is `true` }
  • Before entering the loop, the condition in parentheses is checked. If it’s true, the loop runs.
  • After each run, the condition is checked again. If still true, it repeats.
  • When the condition becomes false, the loop stops and the program continues.
Note
Note

It is important to remember that while loops can be infinite if the condition never becomes false. Remember, it is essential to check the condition carefully.

main.dart

main.dart

copy
12345678
void main() { int counter = 0; while (counter < 5) { print(counter); counter = counter + 1; } }

The while loop runs as long as counter is less than 5. Since counter starts at 0, the loop executes five times, increasing counter by 1 on each iteration.

question-icon

What does the syntax of a while loop look like?

Click or drag`n`drop items and fill in the blanks

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 4. Kapitel 2

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you show me a complete example of a while loop in Dart?

What happens if the condition in the while loop is never false?

Can you explain the difference between a while loop and a for loop?

Awesome!

Completion rate improved to 4.55

bookwhile Loop in Dart

Swipe um das Menü anzuzeigen

A while loop is a programming construct that allows you to execute a specific block of code as long as a certain condition is true.

The syntax for a while loop in Dart is as follows:

loop.dart

loop.dart

copy
123
while (condition) { // Statements to be executed while a condition is `true` }
  • Before entering the loop, the condition in parentheses is checked. If it’s true, the loop runs.
  • After each run, the condition is checked again. If still true, it repeats.
  • When the condition becomes false, the loop stops and the program continues.
Note
Note

It is important to remember that while loops can be infinite if the condition never becomes false. Remember, it is essential to check the condition carefully.

main.dart

main.dart

copy
12345678
void main() { int counter = 0; while (counter < 5) { print(counter); counter = counter + 1; } }

The while loop runs as long as counter is less than 5. Since counter starts at 0, the loop executes five times, increasing counter by 1 on each iteration.

question-icon

What does the syntax of a while loop look like?

Click or drag`n`drop items and fill in the blanks

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 4. Kapitel 2
some-alt