What is the importance of looping because I can't find it a use | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the importance of looping because I can't find it a use

28th Feb 2017, 4:44 PM
kero beshay
kero beshay - avatar
4 Answers
+ 2
loops are used where conditions need to be tested more than once or in a do while loop, at least once. e.g. you have a app where people invest in other accounts, now you need to produce a list of highest investors in a table. you use a foreach loop (php) to create a row in the table for each of the top 10 investors.
28th Feb 2017, 4:58 PM
Andre van Rensburg
Andre van Rensburg - avatar
0
Loop is very useful in many cases. I'll say some of them suppose you want to print all even numbers less than 100. you can do it will looping than writing code for all the numbers one by one. or of you want to display all prime numbers in a range or you want to implement a matrix, generate patterns with numbers or symbols loops are really helpful.it reduces big lines of codes n also useful when same steps has to be repeated based on a given condition.
28th Feb 2017, 4:57 PM
Sebin Poulose
0
Depending on the programming language or task you may have a list of objects, let's say student names, and you need to create accounts for them in a database. It would be easier if a script or program could read each entry in the list and perform a series of actions and then pick up the next entry in the list and repeat. This is the basic idea. Another example would be an array of numbers. If the array is populated by the user and not preprogrammed, the program has to iterate through the positions as data is read or written. This is where a loop can be used to enter each number and then advance to the next position. Same if you are pushing onto or popping off of a stack or heap.
28th Feb 2017, 5:02 PM
Nathaniel Triplett
Nathaniel Triplett - avatar
0
Loops let you test a condition multiple times. Example, you need a code to write multiplication table of 2 .Insted pf printing 2,4,6,8,..etc , you can use a single loop to reach 2 * 10000000 or more
28th Feb 2017, 5:04 PM
Meharban Singh
Meharban Singh - avatar