Header Ads

                                            C Programming - Lecture 7: For loop

For Loop


We have seen the while loop. Now we have more features than the for loop will discuss arakatu. In all cases, the two can not replace each other in the loop with slight variations.

The syntax for loop
for ([init-stmt]; [CONDITION]; [increment-stmt]) 
[Block] 
}
Loop [init-stmt] in place of one or more variables can be assigned. [Condition] is a Boolean expression. True as long as the standard is the expression of the loop as a while loop run.
The end of the [increment-stmt] place of one or more variables can be changed. Here are three parts separated by semicolons. If you wish to exclude any part or all of what we can exclude. However, the semicolon is mandatory. Thus, as written in the research:
for (;;)
{
    [Block]
}
The lupai not ever stop. If you want to use the break to stop the loop. Using the break can be stopped at any time for or while loop.
Now we'll change lupatake while before using for loop.

1. int num;
II. num = 0;
3.
4. while (num <4)
5. {
6. printf ( "% d", num);
7. num = num + 1;
8. }
9.
10.
Using the text at the top of the loop program for states that:
1. int num;
II. num = 0;
3.
4. for (; num <4;)
5. {
6. printf ( "% d", num);
7. num = num + 1;
8. }
9.
10.
Here we have no change. Just used for loop and while loop the loop for conditions where the conditions to enter (after the semicolon) written there. It's exactly the same thing - even though in this case we've used for the loop.
Now we are num = 0 in the loop for part of the move.
1. int num;
II.
3.
4. for (num = 0; num <4;)
5. {
6. printf ( "% d", num);
7. num = num + 1;
8. }
9.
10.
num = 0, we get an eyeball loop [init-stmt] of the place (before the semicolon) wrote. Again, the same program as the program will work.
Here is the latest work of the num = num + 1 stetamentatake for lupara yaoyah
1. int num;
II.
3.
4. for (num = 0; num <4; num = num + 1)
5. {
6. printf ( "% d", num);
7.
8. }
9.
10.
This time, however, there was no change in the program of work was very short.
And while the video below for more discussion tulanasulaka loop written using two programs.
Convert while loop to a for loop

Compare for loop and while loop

No comments:

Powered by Blogger.