|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/cs256su21code/jun07/loop.c
#include <stdio.h>
int main()
{
/*
for loops have three parts
from left-to right
initialization - we do this step only once, we mark the starting point
condition - as long as this statement is still true, do the stuff inside the loop
update - do this, then check the condition to see if it's still true
if so, do the for loop again, otherwise quit
for(initialization; condition; update){
do stuff...
}
*/
int i;
for(i = 1; i <= 10; i++){
printf("%d\n", i);
}
printf("You printed %d numbers.\n", i-1);
return 0;
}
|