[Tutor] Looping quesion [WAS: Re: (no subject)]

Alan Gauld alan.gauld at btinternet.com
Sat Sep 5 10:15:08 CEST 2009


Please always put a meaningful subject line in when you post.

<kb1pkl at aim.com> wrote in message 

>I know, I'm a total noob (started yester day) 
> But when I enter this code:
> x = 1
> if x>0:
> ??? a = raw_input ("Type something in...I will echo it:")
> ??? print a
> ??? x=x+1
> it does not loop..am I missing something here?

Yes, a loop.
Python has two loop constructs: for and while.

If you replace the if test with a while test it will do 
what you want I think. 

while x>0:

Except that it will never stop looping!
You might want to consider putting a mechanism for 
stopping in there :-)

But any reasonable tutorial for beginners should cover 
loops.

Try mine for example... :-)


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list