How Can i guess the correct number that will result from the loop ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How Can i guess the correct number that will result from the loop ?

as you know there is a lot of questions about the loop but I still don't know how can I know exactly guess the number that will result , I find a difficult because the loop is used to print a value many times that means that there's many numbers may be printed, what i have thaught is that the answer is the last number before the loop ends ,so what's the solution? so can someone help me?

10th Feb 2017, 3:49 PM
Hassan Sahlaoui
Hassan Sahlaoui - avatar
3 Answers
+ 2
depends on rules of language, type of loop, e.g. do while and while are different, and the incremental or decremental factor, again e.g. >10 means 11 where >=10 means 10. Best is to say it as you read it, greater than, greater than OR equal to... etc.
10th Feb 2017, 7:36 PM
Andre van Rensburg
Andre van Rensburg - avatar
+ 2
Sometimes, it's nice to know what your loop would produce, especially when you need a specific outcome. However, if your loop makes use of randomness for its output, you might not even have a clue; only a range of values might be all you have. A lot of times, you may need to fine-tune the values you feed the loop. All with trial and error. For simple loops where you increase/decrease a variable's value by a fixed value, use Newton's first equation of motion: v = u + at. Where u is the starting value, a is the incremental value and t is the number of iterations. Well, that's all I have for now.
10th Feb 2017, 8:52 PM
John
John - avatar
0
Anyway thanks a lot my Friend John and Andre for your answers ! it's really interesting!
10th Feb 2017, 9:15 PM
Hassan Sahlaoui
Hassan Sahlaoui - avatar