The for loop is used to repeat a section of code known number of times. Sometimes it is the computer that knows how many times, not you, but it is still known. Some examples:
Unknown number of times:
"Ask the User to Guess a pre-determined number between 1 and 100". You have no way of knowing how many guesses it will take.
"Randomly look in an array for a given value." You have no way of knowing how many tries it will take to find the actual value.
Note: this is a made-up example, because you would never randomly look into an array to find a value. You would always start at the front of the array and look one element at a time until you found the item or got to the end of the array.
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.
Answers & Comments
[tex]\huge\mathcal{\fcolorbox{aqua}{azure}{\red{➳Aɳʂɯҽɾ}}} [/tex]
The for loop is used to repeat a section of code known number of times. Sometimes it is the computer that knows how many times, not you, but it is still known. Some examples:
Unknown number of times:
Note: this is a made-up example, because you would never randomly look into an array to find a value. You would always start at the front of the array and look one element at a time until you found the item or got to the end of the array.
Explanation:
Answer:
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.
Explanation:
Hope it's helpful to you.