Welcome to My Website

HOW DOES A FOR LOOP WORK? JAVASCRIPT EDITION

For loops are loops that go on until a point has been reached.

for(var i = 0;i<10;i++){
	//code
}
				

The code above is the syntax for a for loop. Assuming already have an idea on what javascript opporators do and are here is a simple break down on how a for loop work.


The for loop can be divided into 3 different sections the first one the starting point. Second, the end point and the third the incrementation (how much the loop will go up by).

	starts at zero       Ends at 10      goes up by 1
for ( var start = 0;     start < 10;     start++ ) {
	console.log("Hello!");
}
				

The code that sits with in the loop will fire the amount of times you set the for loop till. For example here is what the output will look like if we use the code above.

Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!