|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/cs256su21code/jun01/count.c
/*
Demonstrating a very simple while loop.
Here, we're just counting from 1 to 10
*/
#include <stdio.h>
int main()
{
int num = 1;
/*
before we start this while loop, we must make sure we declare the variable and then
initalize it to the value we are starting with
*/
while(num <= 10){
/*
as long as what's inside the parenthesis is true, we will repeat what's
inside these brackets.
*/
printf("%d\n", num); //printing the current number
num++; //this is the increment operator, here we add 1 to num.
/*
if we don't want the while loop to go on forever, we need something
that updates the value we're checking inside the parenthesis
*/
}
return 0;
}
|