while Loops

Overview

When using the word “while” in a sentence, we relate it to the construct of time. In English, “while” can be used as a conjunction, indicating the occurrence of one event while another one is in place. For instance, you can say “I am reading a book while my sister is getting ready”. This sentence is indicating that the event, reading a book, will continue to take place as long as the event sister is getting ready is in place.

A while loop in Dart behaves the same way. One event is a condition and the other event is a body of code to be executed. The body of code will be executed repeatedly again and again as long as the condition is being fulfilled (holds true).

Control flow

Let’s look at the control flow of a while loop below.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy