Skip to content

Instantly share code, notes, and snippets.

@froilan-miranda
Last active January 11, 2017 22:04
Show Gist options
  • Save froilan-miranda/c7d99fdf6325e11457559963fc838fd3 to your computer and use it in GitHub Desktop.
Save froilan-miranda/c7d99fdf6325e11457559963fc838fd3 to your computer and use it in GitHub Desktop.

This document is a brief example of the commonalities and differences of execution controll in several languages

If/Else

Java

if (isTrue){ 
  // run some statements     
}else{
  // run some other statements
}

Javascript

if (isTrue){ 
  // run some statements     
}else{
  // run some other statements
}

C#

if (isTrue){ 
  // run some statements     
}else{
  // run some other statements
}

Swift

if isTrue {
  // run some statements
}else{
  // run some other statements
}

Python

if isTrue:
   // run some statements
else:
   // run some other statements

C++

if( isTrue ) {
  // run some statements
} else {
  // run some other statements
}

While

Java

while (count < 11) {
  count++;
}

Javascript

while (count < 11) {
    count++;
}

C#

while (count < 11) {
    count++;
}

Swift

while count < 11 {
  count += 1
}

Python

while (count < 11):
   count += 1

C++

while(count < 11) {
  count++
}

For

Java

for(int i=1; i<11; i++){
  // run some statements
}

Javascript

for (int i=1; i<11; i++) {
    // run some statements
}

C#

for (int i=1; i<11; i++) {
    // run some statements
}

Swift

c-style for loop has been removed

Python

has no c-style for loop

C++

for(int i=1; i<11; i++) {
  // run some statements
}

ForEach

Java

for (String item : someList) {
  // run some statements
}

Javascript

for (let item of someArray) {
  // run some statements
}

C#

foreach (string item in someList)
{
  // run some statements
}

Swift

for item in someList {
  // run some statements
}

Python

for item in someList:
  // run some statements

C++

c++ standard library does not have for each loop

Switch

Java

switch (someInt) {
  case 1:  
    // run some code
    break;
  case 2:  
    // run some other code
    break;
  default: break;
}

Javascript

switch (someInt) {
  case 1:  
    // run some code
    break;
  case 2:  
    // run some other code
    break;
  default: break;
}

C#

switch (someInt) {
  case 1:  
    // run some code
    break;
  case 2:  
    // run some other code
    break;
  default: break;
}

Swift

switch someInt {
case 1:
    // run some code
case 2:
    // run some other code
default:
    print("Some other character")
}

Python

has no switch statement

C++

switch(someInt) {
  case 1 : 
    // run some other code
    break;
  case 2 : 
    // run some other code
    break;
  default:
    break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment