Program in C (Looping)
This is a loop that will continue up to 100.Welcome to the looping section of the programming in C series.
Looping, in C, is simply looping. It is rerunning code, words, numbers, etc. Using a for in the loop commands it has three different parts:
A setup
The part that loops
and the condition where it finishes (if it does)
To explain the code I will use a sample program below:
#include <stdio.h> /*Remember this?*/
int main() /*Standard for programs.*/
{
int c;
for(c=0;c<100;c=c+1)
{
puts("This is a loop that will continue up to 100.");
}
return(0);
}
You see that in that program I defined c. This is an extremely important part of the program. It is similar to symbolic representation, so we could have just used either x, y, z, w, etc, though it is good, when not building a program over 25+ files to keep it to one letter. After that I included: for(c+0;c<100;c=c+1) which simply tells the computer that c is currently defined as 0 and that if it is under 100, which it obviously is, add 1 because it redefines c to equal +1.It stops at 100 because it has code that contains c<100, under 100.If you were to compile it, the program should output:
This is a loop that will continue up to 100.
This is a loop that will continue up to 100.
This is a loop that will continue up to 100.
etc.
Will Continue...