Page 23 - Dart Language
P. 23

Chapter 6: Control Flow




        Examples



        If Else


        Dart has If Else:


         if (year >= 2001) {
           print('21st century');
         } else if (year >= 1901) {
           print('20th century');
         } else {
           print('We Must Go Back!');
         }


        Dart also has a ternary if operator:


         var foo = true;
         print(foo ? 'Foo' : 'Bar'); // Displays "Foo".



        While Loop


        While loops and do while loops are allowed in Dart:


         while(peopleAreClapping()) {
           playSongs();
         }


        and:


         do {
           processRequest();
         } while(stillRunning());


        Loops can be terminated using a break:


         while (true) {
           if (shutDownRequested()) break;
           processIncomingRequests();
         }


        You can skip iterations in a loop using continue:


         for (var i = 0; i < bigNumber; i++) {
           if (i.isEven){
             continue;
           }
           doSomething();



        https://riptutorial.com/                                                                               18
   18   19   20   21   22   23   24   25   26   27   28