0

Basically, I am trying to create a game. It's going well so far! However, I am trying to figure out how to make code go back. I am a beginner at python, so I think its something to do with def start(): and start(): - or something along those lines - but I'm not sure.

If you do not know what I am talking about, I am basically saying I want something like:

    (1) if (variable) == (whatever)
    (2)     print ("Cool you win")
    (4) (code to go back and repeat line 1)
    (5) else:
    (6)     print ("You loose!")
    (7) (code to go back and repeat line 1)

So, basically like a loop: How can I do this?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Ice
  • 9
  • 1
  • 3
  • If you need 'basically like a loop' then just use a loop. – Bill the Lizard Oct 26 '16 at 22:53
  • @BilltheLizard I know the question is quite basic, but is it that bad? I mean, quite often I find questions considered valid here at stackoverflow which can be easily answered by looking up the manual. – Luis de Arquer Oct 27 '16 at 13:24
  • @LuisdeArquer Yes, it's really that bad. There are literally thousands of questions already on Stack Overflow where you can find the basic syntax for a loop, not to mention thousands of other resources on other sites. This is not something that's ever going to help other users. – Bill the Lizard Oct 27 '16 at 13:58
  • @BilltheLizard The question is well-worded and clear, and possibly the OP has never coded a loop or doesn't even know that a loop is possible in programming. Usefulness for other users is desirable, but required? It is useful for OP. And you never [know](http://stackoverflow.com/questions/27364956/looping-back-to-specific-point-in-code). I've seen famous questions that could be solved with a quick google search instead, and they surely were not famous at the moment they were asked. Nothing to argue about question duplicity though. – Luis de Arquer Oct 27 '16 at 14:44
  • @LuisdeArquer The OP wrote "basically like a loop" right in the question. – Bill the Lizard Oct 27 '16 at 14:46
  • @BilltheLizard And yet OP was probably genuinely stuck at it. Many people get stuck at the simplest things when starting to program. I was no exception. Sure, easier googling than asking (but not like OP is spamming the site, and I have seen cases [before](http://stackoverflow.com/questions/9081/grep-a-file-but-show-several-surrounding-lines) ). I don't see anything wrong with the question. – Luis de Arquer Oct 27 '16 at 15:30

1 Answers1

0

You want to use a while loop

while <condition>:
(1) if (variable == whatever):
(2)     print ("Cool you win")
(4) #nothing needed here
(5) else:
(6)     print ("You loose!")
(7) #nothing needed here

If you don't have a particular condition, you can just loop forever with while True:

Luis de Arquer
  • 377
  • 2
  • 8