Nearby lessons

17 of 40

๐Ÿ”‚ JavaScript for Loop

๐Ÿ“Œ What is JavaScript for Loop?

The for loop repeats a block of code a specific number of times.

Perfect when you know exactly how many iterations you need.

๐Ÿ“‹ for Loop Basics

AttributeDescription
Syntaxfor (initialization; condition; increment)
InitializationExecutes once before loop starts
ConditionEvaluated before each iteration
IncrementExecuted after each iteration

๐Ÿ”นPrint 1 to 10 Using for loop

Code Example
PREVIEW READY
Loading Editor...
Live Preview

๐Ÿ”นPrint 10 to 1 Using for loop

Code Example
PREVIEW READY
Loading Editor...
Live Preview

๐Ÿ”นPrint Even Number Using for loop

Code Example
PREVIEW READY
Loading Editor...
Live Preview

๐Ÿ”นPrint Odd Number Using for loop

Code Example
PREVIEW READY
Loading Editor...
Live Preview

๐Ÿ” Nested for Loops

AttributeDescription
UsageCreating grids/multi-dimensional arrays
Outer LoopControls rows
Inner LoopControls columns
Code Example
PREVIEW READY
Loading Editor...
Live Preview

๐Ÿง  Test Your Knowledge

2 Questions

Progress: 0 / 2
Keep Going!JS - While Loop