Blogs

Conditionals

While programming, most of the time a decision needs to be made, therefore we have the conditional tools, that help ups model such decisions

If and Else

Syntax
if (*some condition is true*){
  // do this code
} else if (*other condition*) {
 // Otherwise, do this code if match the other condition
} else { 
 // Otherwise, do this code 
}

Sample

Loops

Loops are useful to iterate a given number of times based on a given condition

While loop

Syntax
while(condition){
  // code
}​

Sample

var amountOfIterations = 10;
var currentIteration = 1;

while (currentIteration <= amountOfIterations){
  console.log("this is the current iteration : " + currentIteration );
  currentIteration++;
}

For loop

Pages

Subscribe to RSS - blogs