An Interest In:
Web News this Week
- April 15, 2024
- April 14, 2024
- April 13, 2024
- April 12, 2024
- April 11, 2024
- April 10, 2024
- April 9, 2024
April 10, 2023 05:05 pm GMT
Original Link: https://dev.to/max24816/javascript-for-loop-380f
JavaScript for loop
Javascript for loop is used execute a block of code repeatedly, based on a condition, until the condition is no longer true. In this article you will learn how for loop works.
Syntax of the Javascript For Loop
for (initialization; condition; increment/decrement) { // code block to be executed}
for loop require three element to make it works,
initialization
used to declare or set a value before starting the loop.
condition
block will be executed for each iteration in the loop, this will evaluate from the start. If the condition fails then the loop will be terminated.
increment / decrement
block will execute at the end of each iteration. It usually increments or decrements the counter variable.
Javascript Program to Check if a Number is Odd or Even
for (let i = 1; i <= 10; i++) { if(i % 2 == 0) { console.log(i); }}
Output
246810
Original Link: https://dev.to/max24816/javascript-for-loop-380f
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To