Understand the FOR loop

This post was originally posted in my first blog — learntheprogramming.blogspot.com

A “for” loop allows code to be repeatedly executed and is classified as an iteration statement.
Unlike many other kinds of loops, such as the while loop, the for loop is often distinguished by an explicit loop counter or loop variable. This allows the body of the for loop (the code that is being repeatedly executed) to know about the sequencing of each iteration.For loops are shorthand way to make loops when the number of iterations is known, as a for loop can be written as a while loop.

Syntax :
for( initialization ; condition ; increment or decrement){//    statements}

This loop will start with giving a variable a value and then keep on executing the body part of the loop as long as the given condition is true. Every time the loop is executed, the variable gets a new value.
Go through this video for complete explanation :

Don’t forget to mention your valuable comments and suggestions.

Leave a Comment