mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 14:32:24 +00:00
912005267d
Change-Id: I46be49b2effec3e38a3dc44cd45cfe736f77fa78 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182680 Commit-Queue: Sigmund Cherem <sigmund@google.com> Reviewed-by: Joshua Litt <joshualitt@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com> Reviewed-by: Stephen Adams <sra@google.com>
91 lines
1.5 KiB
Dart
91 lines
1.5 KiB
Dart
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// @dart = 2.7
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
void for1() {
|
|
var cond = true;
|
|
var result = 0;
|
|
for (var x = 0; cond; x = x + 1) {
|
|
if (x == 10) cond = false;
|
|
result = result + x;
|
|
}
|
|
Expect.equals(55, result);
|
|
}
|
|
|
|
void for2() {
|
|
var t = 0;
|
|
for (var i = 0; i == 0; i = i + 1) {
|
|
t = t + 10;
|
|
}
|
|
Expect.equals(10, t);
|
|
}
|
|
|
|
void for3() {
|
|
for (var i = 0; i == 1; i = i + 1) {
|
|
Expect.fail('unreachable');
|
|
}
|
|
}
|
|
|
|
void for4() {
|
|
var cond1 = true;
|
|
var result = 0;
|
|
for (var i = 0; cond1; i = i + 1) {
|
|
if (i == 9) cond1 = false;
|
|
var cond2 = true;
|
|
for (var j = 0; cond2; j = j + 1) {
|
|
if (j == 9) cond2 = false;
|
|
result = result + 1;
|
|
}
|
|
}
|
|
Expect.equals(100, result);
|
|
}
|
|
|
|
void for5() {
|
|
var i;
|
|
var sum = 0;
|
|
for (i = 0; i < 5; i++) {
|
|
sum += i;
|
|
}
|
|
Expect.equals(5, i);
|
|
Expect.equals(10, sum);
|
|
}
|
|
|
|
void for6() {
|
|
var i = 0;
|
|
var sum = 0;
|
|
for (; i < 5; i++) {
|
|
sum += i;
|
|
}
|
|
Expect.equals(5, i);
|
|
Expect.equals(10, sum);
|
|
|
|
sum = 0;
|
|
i = 0;
|
|
for (; i < 5;) {
|
|
sum += i;
|
|
i++;
|
|
}
|
|
Expect.equals(5, i);
|
|
Expect.equals(10, sum);
|
|
|
|
sum = 0;
|
|
for (i = 0; i < 5;) {
|
|
sum += i;
|
|
i++;
|
|
}
|
|
Expect.equals(5, i);
|
|
Expect.equals(10, sum);
|
|
}
|
|
|
|
void main() {
|
|
for1();
|
|
for2();
|
|
for3();
|
|
for4();
|
|
for5();
|
|
for6();
|
|
}
|