Write a program to explain ""for loop""
Answers
This means that a repeat loop will always execute the process part at least once. tap diagram to zoom and pan
༶•┈┈⛧┈♛Ritika♛┈⛧┈┈•༶
Write a program to explain ""for loop""
Explanation:
Example of For loop in C language:
#include <stdio.h>
int main()
{
int i;
for (i=1; i<=3; i++)
{
printf("%d\n", i);
}
return 0;
}
Output
1
2
3
Explanation
Step 1: In for loop, initialization is done first that means the counter variable i, gets initialized to 1 in above example i.e i = 1.
Step 2: After initialization, the condition is evaluated means the counter variable is checked for the given condition i.e. i<=3, if the condition is true then statement printf("%d\n", i) gets executed by printing the value of i, if the condition false, loop will terminate and the control exists for loop.
Step 3: After executing statement printf() successfully within the body of loop, the counter variable i incremented by 1 and step 1 executes till i<=3