I hope you can answer these simpler questions, and then translate them into your original questions.
Outside/inside (or what is repeated): How many times is the user prompted? Answer that question to yourself with either one or zero to infinity.
Remember that a loop is a way to get something you wrote once to happen many times. If you write the code that reads from the user once, and then want it to actually happen many times, you must enclose that code in a loop. Then you must instruct the loop how to repeat the inner part.
Foreach / while (or how it is repeated): Do you know how many items you will have in advance? A foreach loop takes an array that is already filled up and then runs the enclosed part once for each element.
A while loop reiterates as long as a condition is true. Is the user finished inputing data? asks the question "are we done?". This translates to while the user hasn't finished entering data, or more simply while the user still wants to enter data. Compare this with for each piece of data the user entered.
I hope this makes things clearer =)
In reply to Re: seeking advice on loops
by nothingmuch
in thread seeking advice on loops
by sierrastar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |