for Loop - Devbhoomi

FREE JOB ALERT & ONLINE TUTORIALS

Hot

Post Top Ad

Sunday 5 November 2017

for Loop

Loops are used to repeat a block of code.
Syntax of for Loop :
 for (init; condition; increment)
 {
    // block of statement.
 }
Example :

    #include <stdio.h>

    int main()
    {
    int i;

    for(i = 0; i < 10 ; i++)
    {
    printf("%d ",i);
    }
    return 0;
    }

Output :
 1 2 3 4 5 6 7 8 9 10
Explanation :
init - Initializes the variable at the beginning of the loop to some value. This value is the starting point of the loop.
condition - Decides whether the loop will continue running or not. While this condition is true, the loop will continue running.
increment - The part of the loop that changes the value of the variable created in the variable declaration part of the loop. The increment statement is the part of the loop which will eventually stop the loop from running.

No comments:

Post a Comment

Post Top Ad