Conditional structures
AppleScript
if-then-else
if myVar is "ok" then return true
set i to 0 if i is 0 then return "zero" else if i mod 2 is 0 then return "even" else return "odd" end if
C
if-then-else
Compiler: GCC 4.1.2
int main (int argc, char ** argv) { int input = 2; if ( 3 == input ) { // Do something } if ( 3 == input ) { // Do something } else { // Do something else } }
switch
Compiler: GCC 4.1.2
int main (int argc, char ** argv) { int input = 42; switch (input) { case 0: // Do something, because input = 0 break; case 1: // Do something, because input = 1 break; case 2: // Do something, because input = 2 default: // Do something else. break; // Optional } }
C++
Run-Time Control Structures
if-then-else
Compiler: GCC 4.1.2
int main (void) { int input = 2; if ( 3 == input ) { // Do something }
if ( 3 == input ) { // Do something } else { // Do something else } }
switch
Compiler: GCC 4.1.2
int main (void) { int input = 42; switch (input) { case 0: // Do something, because input = 0 break; case 1: // Do something, because input = 1 break; case 2: // Do something, because input = 2 // Because there is no 'break', we also fall through // into the default case, executing it right after case 2: default: // Do something else. break; // Optional } }