for loop in C
The for loop in C language is also used to iterate the statement or a part of the program several times, like while and do-while loop.
But, we can initialize and increment or decrement the variable also at the time of checking the condition in for loop.
Unlike do while loop, the condition or expression in for loop is given before the statement, so it may execute the statement 0 or more times.
When use for loop in C
For loop is better if number of iteration is known by the programmer.
Syntax of for loop in C
The syntax of for loop in c language is given below:
Flowchart of for loop in C
Example of for loop in C language
Let's see the simple program of for loop that prints table of 1.
Output
1243 586 7 910
C Program : Print table for the given number using C for loop
Output
Enter a number: 22 4 6 8 10 12 14201618
Enter a number: 10001000 2000 3000 400090005000 6000 7000 800010000
Infinitive for loop in C
If you don't initialize any variable, check condition and increment or decrement variable in for loop, it is known as infinitive for loop.
In other words, if you place 2 semicolons in for loop, it is known as infinitive for loop.
If you run this program, you will see above statement infinite times.
No comments:
Post a Comment