Created with <3 with dartpad.dev.
Created
December 20, 2022 06:52
-
-
Save andre-nk/37a2ae95fb93c3e42caa3dea8f0aed9e to your computer and use it in GitHub Desktop.
control-flows
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
void main() { | |
//Boolean expressions | |
//1. Equality | |
const t1 = 1 == 1; //true | |
const t2 = 1 != 2; //true | |
String s1 = "Dog"; | |
bool t3 = s1 == "Cat"; //false | |
//2. AND, OR | |
const andFalse = 1 < 2 && 3 > 4; //false | |
const orFalse = 1 == 2 || 3 == 4; //false | |
//3. If Else and Switch | |
if (s1 == "Dog") { | |
print("Woof!"); | |
} else if (s1 == "Meow") { | |
print("Meow!"); | |
} else { | |
print("RAWRRR!"); | |
} | |
switch (s1) { | |
case "Dog": | |
print("Woof!"); | |
break; //Preventing the flow to flood to default | |
default: | |
print("RAWRRR!"); | |
} | |
//4. Ternary Operators | |
String sound = (s1 == "Dog") ? "Woof!" : "RAWRRR!"; | |
//5. Loops | |
for (int i = 0; i < 10; i++) { | |
if (i == 2) { | |
continue; | |
} | |
print("RAWRRR!"); | |
//break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment