Skip to content

Instantly share code, notes, and snippets.

@r3dm1ke
Created November 25, 2019 20:29
Show Gist options
  • Save r3dm1ke/569297e285380bfc3f5876ad905da36a to your computer and use it in GitHub Desktop.
Save r3dm1ke/569297e285380bfc3f5876ad905da36a to your computer and use it in GitHub Desktop.
Control flow statements in Dart
import 'dart:io';
void main() {
// Read some text from console
var password = stdin.readLineSync();
// Check if password is correct
if (password == 'abc') {
print('Access granted');
} else if (password == 'xyz') {
print('Some access granted');
} else {
print('Go away');
}
// Greet every user personally
var users = ['Bob', 'John', 'Steve'];
for (var user in users) {
print('Hello, ' + user);
}
// Print out squares of numbers from 0 to 4
for (int i = 0; i < 5; i++) {
print(i * i);
}
// Print out powers of 2 less than 10
var j = 1;
while (j < 10) {
print(j);
j *= 2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment