LoOP code code example

Example 1: for loop

for(int i = 0; i < some_number; i++){
  	//inside loop do whatever you want
}

Example 2: loop javascript

for (var i = 0; i < cats.length; i++) {
  if (i === cats.length - 1) {
    info += 'and ' + cats[i] + '.';
  } else {
    info += cats[i] + ', ';
  }
}

Example 3: for loops

MyString = ""
for i in range(5):
  MyString += "hi"
print(MyString)

Example 4: code for loop

for (initializationStatement; testExpression; updateStatement)
{
    // statements inside the body of loop
}

Example 5: loops javascript

/*Loops are great tools when you need your program to run a code block a 
certain number of times or until a condition is met, but they need a 
terminal condition that ends the looping. Infinite loops are likely to 
freeze or crash the browser, and cause general program execution mayhem, 
which no one wants.

Infinite loop example(do not call this function!):*/
function loopy() {
  while(true) {
    console.log("Hello, world!");
  }
}

/*Loop example with terminal condition:*/
function myFunc() {
  for (let i = 1; i <= 4; i += 2) {
    console.log("Still going!");
  }
}

Tags: