Question on Do\While

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.

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.

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.