Control Flow Review conditional statements, loops, and assertions

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.
Get Unlimited PRO Access

OR


*Enrollment provides full access to this course (and updates) for life.

Conditional Statements

file_type_dartlang control-flow.dart
  String color = 'blue';

  if (color == 'blue') {
    //
  } else if (color == 'green') {
    //
  } else {
    // default
  }

  // One liner
  if (color == 'red') print('hello red!');

Loops

file_type_dartlang control-flow.dart
  for (var i = 0; i < 5; i++) {
    print(i);
    // break;
    // continue;
  }

  int i = 0;
  while (i < 5) {
    print(i);
    i++;
  }

  i = 0;
  do {
    print(i);
  } while (i < 5);

Assertions

file_type_dartlang control-flow.dart
  // Assert
  var txt = 'good';
  assert(txt != 'bad');

Q&A Chat