Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 10, 2023 05:05 pm GMT

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

Learn Javascript Tutorial


Original Link: https://dev.to/max24816/javascript-for-loop-380f

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To