+ 1
wht is the main idea of looping?
4 ответов
+ 5
loops repeat an action until you stop them with a condition(if not they would run forever).
They are really useful for not have the same code many times, for example if you want to print something a number of times you will use a loop that ends after a counter that increases every time you make the action reaches that number or something like that.
They are really useful in my opinion 😉
+ 1
//More efficient also, better in checking values and comparing them.
//Here is an example:
cout << "Hello World!" << endl;
cout << "Hello World!" << endl;
cout << "Hello World!" << endl;
cout << "Hello World!" << endl;
cout << "Hello World!" << endl;
//This is way better
for (int i = 0; i < 5; i++) {
cout << "Hello World!" << endl;
}
0
just learn it, you will get the point eventually. I promise it's important and usefull to learn.
0
As stated above, loops are useful and have purpose. Shortening your overall code is definitely a good reason. Depending on the function of your code, your entire program maybe a large cycle to enumerating through a database.
As your skills and experience in development increase, you will understand the need and find uses for loops.