Yes, you can have multiple expressions in the increment poart of the for loop statement. Just use the comma, and each expression will be evaluated from left to right.
For
increment the loop control variable
A for loop.
Counting Loop
It comes from its name: it doesn't terminate, the user have to interrupt the program-run (in the worst case: power off the computer).The infinite loop is also used to program loops with non-easily-deterministically end-of-loop conditions.You write an infinite loop, such as for (;;) {statements}, and break out of the loop with the break statement when ready to terminate.
For
For
for(assigning initial value;condition;increment/decrement) { statement; }
The three main components that control a loop are the initialization, the condition, and the increment/decrement statement. Initialization sets the starting point of the loop, the condition determines when the loop should continue running, and the increment/decrement statement updates the loop variable to progress towards the termination condition. Together, these components ensure that the loop executes the desired number of times and eventually exits when the condition is no longer met.
Do statement : Here the do loop exicutes once without cheching the condition and then the condition will be checked if condition becomes true then again loop begins from do and then exictes here if you are given value is n then loop exictues n+1 times.for statement : Here the for loop will be initilized first and the condition will be checked if the condition then the pointer enters the loop else not.And after completion of the loop the pointer again moves to the for statement and the increment/Decrement will be done as you provided in loop then the condition will be checked if satisfy then it enteres loop else not
increment the loop control variable
A for loop.
FOR loops work as follows:{for( [initialize a variable]; [expression]; [increment the variable] ) {//Do this code}}Here as an example of a FOR loop:{for(i = 1; i < 10; i += 1) {show_message(string(i));}}What this will do is show a message 10 times displaying the value of "i" so you would get a message that says "1," another one after that saying "2," etc... The way this works is that you have the variable "i" initialized in the FOR loop. The FOR loop will keep looping until i >= 10, because the middle statement dictates that i must be smaller than 10 for the FOR loop activate. The third statement in the for loop is the statement that you increment the i variable with. If you change i += 1 to i -= 1 then the FOR loop would go on forever, freezing the game. This is a critical mistake to make when constructing a FOR loop (as is with any loop.)
Counting Loop
for loop
C has 3 types of loops. do { foo += increment; } while(foo != bar); This loop will continue until foo equals bar but will execute the loop at least once, even if foo equals bar. The variable increment may be changed within the do loop. It is imperative that the value foo can reach equality with bar, otherwise an endless (run for ever) loop condition exists. ***** while(foo != bar) { foo += increment; } The loop will continue until foo equals bar but will not execute if foo equals bar. The variable increment may be changed within the do loop. It is imperative that the value foo can reach equality with bar, otherwise an endless (run for ever) loop condition exists. ***** for (foo = 0; foo < bar; foo+= increment) { } The loop will continue until foo equals bar. The stepping amount is controlled by the value of increment. The value of increment could be changed inside the loop.
For Loop:1.In this first it initialized with the starting value such as I=0,count=0.The value which was initialized is then checked with the given test condition. While Loop:1.In this it checks the condition first. for Loop:2.In this we initializ,check conition and increment or dicrement in one statement While loop2:In this only we can test the condition in one statements. For Loop3:general Format: for (initialization; test condition; increment) { body of the loop } While loop:3.general Format while(test condition) { body of the loop }