OneBite.Dev - Coding blog in a bite size

use a basic loop in Javascript

Code snippet on how to use a basic loop in Javascript

  for (let i = 0; i < 10; i++) { 
      console.log(i); 
  }

This code will loop 10 times and output the current iteration number each time. First, the loop is initialized with the statement “let i = 0”. This sets the counter that the loop will use to keep track of how many times it has executed. The “i < 10” part of the statement sets the condition to be checked at the beginning of each iteration, meaning that the loop will continue to execute until “i” is no longer less than 10. Finally, the statement “i++” is used to increment the loop counter at the end of each iteration. This means after each iteration, the current value of i will increase by one. The loop will then execute the code inside the brackets console.log(i) every iteration until the condition is no longer met.

javascript