Programming in Dart: Control Flow & Collections

May 3 2022 Dart 2.15, DartPad, DartPad

Part 1: Control Flow

8. Understand Nested Loops

Episode complete

Play next episode

Next
Save for later
About this episode
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 7. Challenge: Practice Iterating Next episode: 9. Use a Switch Statement

This video Understand Nested Loops was last updated on May 3 2022

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

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;
}