Why to use loop condition | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why to use loop condition

tell me about use loop condition

28th Oct 2017, 11:49 AM
hariharan
hariharan - avatar
2 Answers
+ 2
For example, if you wanna print the sentence "hello world" on the screen 100 times you can use the for loop instead of typing print."hello world " 100 times in your code.
28th Oct 2017, 12:00 PM
WildGeese
WildGeese - avatar
+ 3
Loops allow you to run a segment of code repeatedly - for a number of times or until a condition is met. The condition is "what you want to happen"! So if myValue is True, then my while-loop would run forever; if it was False, it wouldn't run at all. (bool) myValue = true; while myValue { //etcetera blahblah break } You can change the loop condition with a simple: myValue = False; //or True, your choice from inside or outside the loop. Simple stuff! You *will* want to use loops with Loop Conditions to run repeatitive code, unless you want to type your stuff one-by-one, line-by-line. (A painful experience, trust me...)
28th Oct 2017, 11:59 AM
ghostwalker13
ghostwalker13 - avatar