For loop in c with example

For loop is another loop in c.


for(initialization; condition; increment)
Body of the loop


# If body of loop is only one statement than braces ({}) are not needed.
# Body of the loop may have one or more statement.
# Initialization and increment can be skip but semicolon should be there to separate 3 section.
# Condition section can`t be skip in for loop.


In for loop 1st variable is initialized than condition will check if condition is true than body of the loop will executed. After body of the loop is execute, variable is incremented and the condition is again tested if condition is true than again body of loop is executed, this process is repeated until condition is true. When condition is false than statement next to while loop is executed.

For loop can be written in another way by skipping initialization and increment condition.


for( ; condition; )
Body of the loop

Variable can be declared in for loop


for(int i=0; i< num; i++) Note:- for loop initial declaration are only allowed in c99 mode. Example:-

Program to count N numbers

Program to display even number up to 20

Previous Code:-
Decrement operator

List Code:-
C Codes

Next Code:-
while loop

C Programs
List of c Programs

One Comment

Add your comments here

Back to Top