0

What is a loop

14th Nov 2017, 7:42 PM
selva ganesh
6 Answers
+ 6
In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached. Typically, a certain process is done, such as getting an item of data and changing it, and then some condition is checked such as whether a counter has reached a prescribed number. If it hasn't, the next instruction in the sequence is an instruction to return to the first instruction in the sequence and repeat the sequence. If the condition has been reached, the next instruction "falls through" to the next sequential instruction or branches outside the loop. A loop is a fundamental programming idea that is commonly used in writing programs.
14th Nov 2017, 7:44 PM
MsJ
MsJ - avatar
+ 2
imagine ypu need to write "Hi" five times.In C++, you can do this... cout<<"Hi"<<endl; cout<<"Hi"<<endl; cout<<"Hi"<<endl; cout<<"Hi"<<endl; cout<<"Hi"<<endl; But this is an ugly code and also it takes too many times.What would you do if you had write Hi 100 times? Loop gives you its solution.You may write that code much easily...... for(int j=0;j<=5;j++) { cout<<"Hi"<<endl; } You see the code is much smaller and also easier to write.
15th Nov 2017, 5:12 AM
Md. Nafis Ul Haque Shifat
Md. Nafis Ul Haque Shifat - avatar
0
pls give me an example
14th Nov 2017, 7:52 PM
selva ganesh
0
a loop is a thing that repeats a certain amount of times (or infinitely) example int i = 0; while (i <5) { cout << i << endl; i++; } this while loop repeats 5 times because each time you add + 1 to i
14th Nov 2017, 10:03 PM
Eligijus Silkartas
Eligijus Silkartas - avatar