+ 3
Please tell me what is a "LOOP"???
I have sololearn lesson but I can't understand that point only otherwise sololearn is BEST PLZ HELP ME,I AM BEGGINER 14 YRS
5 Réponses
+ 17
Again and again and again and again.... and again and again...and..*stop*
Doing a particular task repetitively everytime a particular condition is True
The task gets terminated when the condition gets False
eg: For Loop
for(int x=0; x<5; x++)
cout<<x;
//Output
01234
In the above loop x=0 is less than 5 so it gets printed and then x++ causes increment (+1) so now x is 1 which is also less than 5 and gets printed.
Moving on to 4 it will increment to 5 which isn't less than 5 so the loop gets terminated.
So the loop was of printing the value of x until a particular condition (<5) was satisfied and once it becomes False the loop ends..
Same goes for while , do while loops
+ 4
it is used to do a particular task again and again.
it's your wish how many times you want that particular task to be repeated, accordingly you write the code.
there are for loop, while loop, do while loop.
based on your requirement and logic use the appropriate loop and write your code.
all the best.
+ 2
Lets say you want to read data from a file. The data is separated on multiple lines and for each line you want to execute a series of commands.
What do you do? You write a while LOOP where the condition is that you still have lines to read.
Basically when you need to execute a command or more command multiple times you use a loop, a while loop when you don't know how many times it should run or a for loop otherwise.
+ 2
Doing repetitive task
Like doing pushups 20x. You'll do pushup repetitively until you do it 20x and then you finally stop
+ 2
Same tasks repeated until an exit condition is met. There are different types of loops. Practice on simple for loops. :)