As we discuss about the Looping in the Previous section, Looping is a process which is used to execute a set of statements repetitively when a certain condition true.
For Loop :
C provides three ways to execute the loops. While all of the ways offer similar basic functionality, but differ in syntax and condition.
|
For Loop :
For loop, the loop structure provides a concise way of writing. Unlike a while loop, a statement consumes the initialization, condition, and increment / decrement in one line, thus creating a shorter, easy to debug looping structure.
Syntax:
for(initialization ; Test Condition ; Increment/ Decrement)
{
Statements or Body of Loop
}
|
1.Initialization: We initialize the variable in use here. It marks the beginning of a for loop. It is possible to use an already declared variable, or to declare a variable, local to loop only.
2. Test Condition: It is used to test a loop's exit condition. They have to return a boolean value. It is also an Entry Control Loop, since the condition is checked before the loop statements are executed.
3. Execution of statements: Once the condition is evaluated to true, the statements are executed in the body of the loop.
4.Increment / Decrement: Used for next iteration to change the variable.
5. Loop termination: When the state is incorrect the loop stops signaling the end of its cycle of life.
Flow Chart of For Loop:
thanks sir g
ReplyDelete