允许两种类型的for循环:
for (int month = 1; month <= 12; month++) { print(month); }
和:
for (var object in flybyObjects) { print(object); }
for-in当简单地遍历一个Iterable集合时,该循环很方便。forEach您还可以调用Iterable行为类似于for-in以下对象的方法:
flybyObjects.forEach((object) => print(object));
或者,更简洁地说:
flybyObjects.forEach(print);