Get immediate access to this and over 1,500+ other videos and books.

Boost your skills with a raywenderlich.com Beginner subscription. With over 60+ video courses and our core foundational programming books bundled in one subscription, it’s simply the best investment you can make in your development career.

Use a Switch Statement

This video was last updated on May 3 2022

Learn how to switch on values using Dart’s switch statement.

Contributors

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 raywenderlich.com Professional subscription.

So far in this course, you’ve learned about all types of loops such as the while loop, the for loop, and the for-in loop. But actually, Dart has another aspect of control flow that allows you to switch on a value.

var trafficLight = 'green';
switch (trafficLight) {

}
case 'green': 
    print('drive');
case 'green': 
    print('drive');
    break;
case 'yellow':
    print('slow down');
    break;
case 'red':
    print('stop');
    break;
    default:
      print('stop');
var trafficLight = 'flashing-yellow';
    case 'red':
    default:
      print('stop');
var trafficLight = 'red';
switch (trafficLight) {
    case 'flashing-red': 
      print('drive to line');
      break;    
redLight:
case 'red':
    print('stop');
    break;
switch (trafficLight) {
    case 'flashing-red': 
      continue redLight;    
var trafficLight = 'flashing-red';

Reviews

Comments