+ 1
what are loops
2 Réponses
+ 1
A loop is a function that continues to run until a certain condition evaluates to false.
while() is a loop. Example:
int x = 0;
while (x != 6)
{
std::cout << x << "\n";
x++;
}
Output will be:
0
1
2
3
4
5
for() is also a loop. Example:
int x = 1;
for (int y = 1; y <= 5; y++)
{
std::cout << x << "\n";
x *= y;
}
Output will be:
1
2
6
24
120
0
loops are used in program when u need to print a thing or perform operation continuously