Programming in Dart: Control Flow & Collections

May 3 2022 · Dart 2.15, DartPad, DartPad

Part 1: Control Flow

08. Understand Nested Loops

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 07. Challenge: Practice Iterating Next episode: 09. Use a Switch Statement

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

So far in this course, you’ve been working with loops that operate over lists; in other words, your loop always goes from start to finish with no interruption.

var daysOfTheWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
for (var day in daysOfTheWeek) {
    print(day);
}
for (var day in daysOfTheWeek) {
    if (day == 'Thursday') {

    }
    print(day);
}
for (var day in daysOfTheWeek) {
    if (day == 'Thursday') {
        break;
    }
    print(day);
}
  for (var day in daysOfTheWeek) {
    if (day == 'Thursday') {
        continue;
    }
    print(day);
  }
var movieOne = ['Peter Jackson', 'Ian Mckellen', 'Viggo Mortensen'];
var movieTwo = ['Jackie Chan', 'Alan Smithee', 'Sylvester Stallone'];
var movieThree = ['Chris Pratt', 'Kurt Russell', 'Sean Gunn'];
var movies = [movieOne, movieTwo, movieThree];
var totalCredits = 0;
var processedMovies = 0;
for (var movie in movies) {
    for (var credit in movie) {
        print(credit);
        totalCredits += 1;
    }
    processedMovies += 1;
}
print('---');
print('total processed movies: $processedMovies');
print('total processed credits: $totalCredits');
  var processedCredit = 0;
  for (var movie in movies) {
    processedCredit = 0;
    for (var credit in movie) {
      print(credit);
      processedCredit += 1;
    }
    totalCredits += processedCredit;
    processedMovies += 1;
  }
if (credit == 'Alan Smithee') {
    break;
}
outerloop:
for (var movie in movies) {
if (credit == 'Alan Smithee') {
    continue outerloop;
}