0

If the question says... "user can enter input up to five times" - does that mean you use a "for loop" since you know the # of times? or do you just use a "while loop" please help. thanks.

6
Contributors
8
Replies
9
Views
9 Years
Discussion Span
Last Post by Sci@phy
0

A loop's a loop. It doesn't matter how you do it. It's entirely equivalent. No matter which you choose all should produce the same five-time iteration that you want. I'd use for but a while would work too.

0

Use whichever makes more sense. In this case it's a counted loop, which is what the for loop syntax was designed to handle.

0

You can use any loop, be it for-loop, or while loop, or do-while loop. For the latter two, you just need to increment the counter within the loop and check for it at the condition place.

0

my problem has to do with - if you enter a number (10) it will output the word (ten) and so on... so I guess like you all said. any loop would work.

0

i think it means that you keep a counter to how many times a user has entered a number and if it exceeds 5 you stop.
So you can to it better with a do while loop because you can specify the exit conditions clearly.

0

There's no point in asking "which loop do I HAVE to use."

Every loop does the same thing. You can try it yourself: write something with for-loop, then try to write same thing with other two loops.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.