Created
November 25, 2019 20:29
-
-
Save r3dm1ke/569297e285380bfc3f5876ad905da36a to your computer and use it in GitHub Desktop.
Control flow statements in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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