| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // Dart test for breaks in for, do/while and while loops. | |
| 5 | |
| 6 import "package:expect/expect.dart"; | |
| 7 | |
| 8 class BreakTest { | |
| 9 static testMain() { | |
| 10 int i; | |
| 11 int forCounter = 0; | |
| 12 for (i = 0; i < 10; i++) { | |
| 13 forCounter++; | |
| 14 if (i > 3) break; | |
| 15 } | |
| 16 Expect.equals(5, forCounter); | |
| 17 Expect.equals(4, i); | |
| 18 | |
| 19 i = 0; | |
| 20 int doWhileCounter = 0; | |
| 21 do { | |
| 22 i++; | |
| 23 doWhileCounter++; | |
| 24 if (i > 3) break; | |
| 25 } while (i < 10); | |
| 26 Expect.equals(4, doWhileCounter); | |
| 27 Expect.equals(4, i); | |
| 28 | |
| 29 i = 0; | |
| 30 int whileCounter = 0; | |
| 31 while (i < 10) { | |
| 32 i++; | |
| 33 whileCounter++; | |
| 34 if (i > 3) break; | |
| 35 } | |
| 36 Expect.equals(4, whileCounter); | |
| 37 Expect.equals(4, i); | |
| 38 | |
| 39 // Use a label to break to the outer loop. | |
| 40 i = 0; | |
| 41 L: | |
| 42 while (i < 10) { | |
| 43 i++; | |
| 44 while (i > 5) { | |
| 45 break L; | |
| 46 } | |
| 47 } | |
| 48 Expect.equals(6, i); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 main() { | |
| 53 BreakTest.testMain(); | |
| 54 } | |
| OLD | NEW |