What is the importance of for loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the importance of for loop?

23rd Jul 2017, 4:31 PM
Prabin Kumar Sahu
Prabin Kumar Sahu - avatar
3 Answers
+ 2
They other day i was sitting in the car, thinking about a script i'm working on. As i sat there i randomnly started wondering how the car was programmed and found that everything must stem from only a few key structures. while loops: while seatbelt not fastened make beeping sound. while left indicator button flash left indicator. for loops: for miles driven sum up all the miles. for driving speed do calculation to get average speed. if petrol tank is running low make beep to indicate etc etc etc when i program i am always using for loops. i m currently working on a program that reads a script, recognises from my commenrs if it is new unlearnt code, from comments identifies end of new code block asks me what the code does, prints it to file and then reads the next script in my directory. for that i need a for loop to read the file and get the line numbers. a for loop write the code to a file a for loop to move from file to file in my directory. for loops just keep popping up everywhere
23rd Jul 2017, 9:00 PM
Michael Bosher
Michael Bosher - avatar
+ 1
Loop is very important and one of my favourite . because we do not have to take plenty of variables , loop help to repeat the process.
23rd Jul 2017, 4:38 PM
Irwin Lopez
Irwin Lopez - avatar
+ 1
😏thats exactly right Mr Immortal
23rd Jul 2017, 4:49 PM
Irwin Lopez
Irwin Lopez - avatar