python line repeat help

Ok, I was just hoping someone would be able to tell me if python has a function that would allow you to go back to a previous line in the script, kind of like goto in command prompt. I’m working on an explosion script and I need a way to repeat a command til certain conditions are met. Thanks for any help.

As far as I know, there is not ‘goto’ statement.

But think about this:
make a function and use a while-loop using that function until your condition is fulfilled?!

Ok, thanks. Just one stupid question. How do I create a function? I’m still fairly new to python. Is it hidden in the python documentation somewhere? Thanks.

this page: http://www.astro.ufl.edu/~warner/prog/python.html helped a lot for me getting started with python.

www.python.org also has some very complete introduction pages.

type def, then the name of your function followed by any variables you want to be local to that function enclosed in parenthesis.
ex.
def function(var1,var2):

or if you don’t have any local variables
def function():
(replace the word function with any name you choose)
heres a quick working example too:

def function(var1,var2):
	while var1 < var2:
		print(var1)
		var1 += 1
function(1,10)

Test it out a couple of times in IDLE, that should give you a better idea of how to use functions.

This is also a very good book to learn python

http://openbookproject.net//thinkCSpy/

Just to clarify what I’m trying to do, an example would be this.
Let’s have a variable n. n = 5. I want to write a script that would reduce n to 0 by subtracting by one, seeing if n = o, then subtracting by one again. I want it to repeat without me having to copy the command over and over, mostly because the value of n will vary.

If I understand well, you want an iteration that would reduce n by 1 until it get to 0. Is it that? If it is, then this script should do it:

n = 5

while n > 0:
    n -= 1

I believe that is exactly what I was looking for actually. Thanks for all the help guys. Ill have to look into the rest of it too.