Iterative sentence
Repetitive action
Computers can repeat the same thing as many times as needed.
If needed, it can be repeated as many times as tens of thousands or even hundreds of millions.
Repetition can be either a fixed number of repetitions or an indefinite number of repetitions.
In C, for loops are used for definite iterations.
The for loop is used in the following format:
This 'i' is an integer variable used to count the number of iterations.
Of course, this `i` needs to be declared before using it in the for loop.
The following program is an example of using a for loop to display a message 10 times.
The output of this program will be as follows:
When I counted, I found it appeared 10 times.
If needed, it can be repeated as many times as tens of thousands or even hundreds of millions.
Repetition can be either a fixed number of repetitions or an indefinite number of repetitions.
In C, for loops are used for definite iterations.
The for loop is used in the following format:
for loop
int i;
for (i = 1; i <= Loop Count; i++) {
Loop Sentence;
}
This 'i' is an integer variable used to count the number of iterations.
Of course, this `i` needs to be declared before using it in the for loop.
The following program is an example of using a for loop to display a message 10 times.
Source code
#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i <= 10; i++) {
printf("Message\n");
}
return 0;
}
The output of this program will be as follows:
Results
Message
Message
Message
Message
Message
Message
Message
Message
Message
Message
Message
Message
Message
Message
Message
Message
Message
Message
Message
When I counted, I found it appeared 10 times.
Count display
I learned that using a for loop allows you to repeat a process.
We refer to the variables used at this time as count variables or loop variables.
The counter variable doesn't have to be 'i', it can be anything you like.
In C, it's conventional to use `i`.
The value of the repetition count can be known at any time by referencing the variable i.
The following program is an example that displays the number of repetitions.
The output of this program will be as follows:
Looking at the results, it's clear it appears 10 times.
We refer to the variables used at this time as count variables or loop variables.
The counter variable doesn't have to be 'i', it can be anything you like.
In C, it's conventional to use `i`.
The value of the repetition count can be known at any time by referencing the variable i.
The following program is an example that displays the number of repetitions.
Source code
#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i <= 10; i++) {
printf("%02d time\n", i);
}
return 0;
}
The output of this program will be as follows:
Results
01 time
02 time
03 time
04 time
05 time
06 time
07 time
08 time
09 time
10 time
02 time
03 time
04 time
05 time
06 time
07 time
08 time
09 time
10 time
Looking at the results, it's clear it appears 10 times.
a vast number of
You might have thought it was fine to write the printf statement ten times if you were only displaying it ten times.
However, in reality, the number of repetitions can be specified virtually without limit.
Computers don't get tired like humans do.Therefore, you can specify it, no matter how frightening the number of times.
まあ、本当に限界を超える無茶をさせると、熱暴走してしまうのですが・・・
The following program is a version with a loop count of 9999.
The output of this program will be as follows:
Modern computers are so powerful that they won't even flinch with around 9,999 iterations.
You can run computers as much as you want, whether it's millions, billions, trillions, or even more.
However, in reality, the number of repetitions can be specified virtually without limit.
Computers don't get tired like humans do.Therefore, you can specify it, no matter how frightening the number of times.
まあ、本当に限界を超える無茶をさせると、熱暴走してしまうのですが・・・
The following program is a version with a loop count of 9999.
Source code
#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i <= 9999; i++) {
printf("%04d time\n", i);
}
return 0;
}
The output of this program will be as follows:
Results
0001 time
0002 time
0003 time
0004 time
0005 time
0006 time
0007 time
0008 time
0009 time
0010 time
0011 time
0012 time
0013 time
0014 time
・
・
~Omitted hereafter~
0002 time
0003 time
0004 time
0005 time
0006 time
0007 time
0008 time
0009 time
0010 time
0011 time
0012 time
0013 time
0014 time
・
・
~Omitted hereafter~
Modern computers are so powerful that they won't even flinch with around 9,999 iterations.
You can run computers as much as you want, whether it's millions, billions, trillions, or even more.
About This Site
Learning C language through suffering (Kushi C) isThis is the definitive introduction to the C language.
It systematically explains the basic functions of the C language.
The quality is equal to or higher than commercially available books.




