Advertisement
/* C - for loop example */
#include<stdio.h>
int main() /*main method starts*/
{
for(int counter = 0; counter<5; counter++)
{
printf("counter = %d \n", counter);
}
return 0;
}/* main method ends and program ends too */
counter = 0
counter = 1
counter = 2
counter = 3
counter = 4
Advertisement
/* C - for loop example */
#include<stdio.h>
int main() /*main method starts*/
{
for(int counter = 0; counter<5; ) /* counter iteration part is intentionally left */
{
printf("counter = %d \n", counter);
counter++ /* counter is incremented/iterated in the body of for-loop */
}
return 0;
}/* main method ends and program ends too */
counter = 0
counter = 1
counter = 2
counter = 3
counter = 4
/* C - for loop example */
#include<stdio.h>
int main() /*main method starts*/
{
for(int counter = 0;; )
{
if(counter<5)
{
printf("counter = %d \n", counter);
counter++;
}
else
break; /* In this case, break statement makes the for loop work */
return 0;
}
}/* main method ends and program ends too */
counter = 0
counter = 1
counter = 2
counter = 3
counter = 4
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement