<Go Back

Here are some notes for our operators and loops reading

what is a loop?

  • Loops offer a quick and easy way to do something repeatedly.A loop can be explained as so: a computerized version of the game where you tell someone to take x steps in one direction, then y steps in another.

For example

for (let step = 0; step < 5; step++) { // Runs 5 times, with values of step 0 through 4. console.log(‘Walking east one step’); }

The statements for loops provided in JavaScript are:

  • for statement
  • do…while statement
  • while statement
  • labeled statement
  • break statement
  • continue statement
  • for…in statement
  • for…of statement

A for loop repeats until a specified condition evaluates to false. Same with the do…while statement.

However a while statemnt executes its statements as long as a specified condition evaluates to true.

For Example

while (condition) statement