Question on Do\While

A35b3ff33784de282d99dda93e669f4e
0
Felthorn 101 Feb 15, 2013 at 00:15

Hey, I have a (probably really stupid and noobish ) question. Do I need to have a condition for a do\while statment. I’ve change my game so that it is far simpler, and right now I’m trying to make a room with two doors in it, and I want the game to ask you which door you want to use every time you enter the main room. Any help will be greatly appreciated. Thanks! :)

2 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Feb 15, 2013 at 07:22

You do need to have a condition, but if you want an infinite loop then you can just use “true” as the condition, as in “do { … } while (true);”.

Actually, most programmers would write an infinite loop as “while (true) { … }” or “for (;;) { … }”, but the do-while form will work as well.

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 103 Feb 15, 2013 at 09:07

watch out for your while loops, if the condition never meets you go on an infinite cycle. preferably leave them out of the code unless you have to.