write a c program using for loop
Q write a name 5 time using for loop
HOW T0 WORK FOR LOOP
- The initialization statement is executed only once.
- Then, the test expression is evaluated.If the check at expression is evaluated to false, the for loop is terminated.
- However, if the take a look at expression is evaluated to true, statements within the body of for loop area unit dead, and therefore the update expression is updated.
- Again the test expression is evaluated.
This method goes on till the take a look at expression is fake.
When the take a look at expression is fake, the loop terminates.
To learn more about test when the test expression is evaluated to true and false), check out relational and logical operators.
PROGRAM
#include <stdio.h>
#include <stdlib.h>
/*
*
*/
int main(int argc, char** argv)
{
int i;
for(i=1; i<=5;i++)
{
printf("SHASHI SHARMA\n");
}
return (EXIT_SUCCESS);
}
- i is initialized to 1.
- The check expression
i <=5
is evaluated. since ONE less and equal to FIVE than given statements is true, the body offor
loop is executed. it will print the shashi sharma on the screen . - The statement i++ is executed. after the value of i will be changed in 2. Again, the check expression is evaluated so it is true, the cursor go to body of for loop and executed. it will print shashi sharma second time on scree.
- Again, check the update statement i++ and execute i<=5, the process goes on again and again i <=5 .
- When i<=5 will be false,then for loop end .
Comments
Post a Comment