🔁 Flow Control: For Loops

Lesson

🔁 Flow Control: For Loops

For Loops

What is For loops?

For statement create a loop that runs a block of code many times.

for (i = 0; i < 5; i++) {
  alert(i);
}

While Loops

What is While loop?

While statement create a loop through a block of code while the condition is true.

let i = 0;         //define value
  while (i < 5) {  //while i < 5 (condition)
    i++;           //when there is not less than 5, end running
    alert(i); 
  }

Here is another example of using while loop!

Do-White Loops

What is Do-While loop?

Do-While statement creates a loop that will run through a block of code first then check if the condition is true or false.

var i = 0;
do{
    alert(i);
    i++;
}while(i<=10);

Here is the example of do-while loop, similar to While loop but different, let’s find out!

Time for a Challenge

Now that you’ve caught up to part 2, it’s time to do Challenge 2: FizzBuzz.

@

Not recently active