Programming in Dart: Control Flow & Collections

May 3 2022 Dart 2.15, DartPad, DartPad

Part 1: Control Flow

3. Challenge: Use While Loops

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 2. Understand While Loops Next episode: 4. Learn For Loops

This video was last updated on May 3 2022

It’s time for your next challenge! Your challenge is to create a loop that counts down from ten and instead of zero, you should print out the words, “Blast Off!”. That’s right, we’re launching rockets from raywenderlich.com - pause the video and now and try it out.

How’d that challenge go for you. Hopefully, it wasn’t too bad. A little resistance will go a long way to make you a better developer. Lets start at the top. Open up a fresh DartPad. Start by creating a new counter variable. Set it to 10.

var counter = 10;

Now comes our while loop. This loop will run so long as the counter is greater than zero.

while (counter > 0) {

}

Next print out the counter then make sure to decrement it.

print(counter);
counter -= 1;

Finally after the loop, print out the text ‘Blast Off!’.

print('Blast Off!');

And that’s it - you have a countdown. Now run the app. We get a countdown followed by the words, Blast Off!.