Skip to content

Instantly share code, notes, and snippets.

@kwalrath
Last active August 29, 2015 14:26
Show Gist options
  • Save kwalrath/836a6f67f4ef7af349bc to your computer and use it in GitHub Desktop.
Save kwalrath/836a6f67f4ef7af349bc to your computer and use it in GitHub Desktop.
for_loops
doFor() {
//BEGIN
var message = new StringBuffer("Dart is fun");
for (var i = 0; i < 5; i++) {
message.write('!');
}
//END
print(message);
}
doClosures() {
print('do closures right: 0 1');
//BEGIN
var callbacks = [];
for (var i = 0; i < 2; i++) {
callbacks.add(() => print(i));
}
callbacks.forEach((c) => c());
//END
}
doCollection() {
print('do collection');
//BEGIN
var collection = [0, 1, 2];
for (var x in collection) {
print(x); // 0 1 2
}
//END
}
class Candidate {
interview() {}
}
doForIn() {
List<Candidate> candidates = [
new Candidate(),
new Candidate(),
new Candidate()
];
//BEGIN
candidates.forEach((candidate) => candidate.interview());
//END
}
main() {
doFor();
doClosures();
doCollection();
doForIn();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment