I donä't get while-loops

2008-08-02 Thread ssecorp
in read2 it never quits when I write quit, why? def read(): expr = raw_input("Lisp> ") if expr != "quit": print parse(expr) read() else: print "Good session!" def read2(): expr = "" while expr != "quit": expr = raw_input("Lisp> ") print

Re: I donä't get while-loops

2008-08-02 Thread Stefaan Himpe
def read2(): expr = "" while expr != "quit": expr = raw_input("Lisp> ") print parse(expr) read2() ^ print "Good session!" You shouldn't call read2() inside read2()... just remove that line and retry... Each time you call read2() recursivel

Re: I donä't get while-loops

2008-08-02 Thread Larry Bates
ssecorp wrote: in read2 it never quits when I write quit, why? def read(): expr = raw_input("Lisp> ") if expr != "quit": print parse(expr) read() else: print "Good session!" def read2(): expr = "" while expr != "quit": expr = raw_input("Lisp>

Re: I donä't get while-loops

2008-08-02 Thread ssecorp
oops, embarrassing, I created the while loop not to use recursion then I still did... -- http://mail.python.org/mailman/listinfo/python-list

Re: I donä't get while-loops

2008-08-02 Thread Tyler Breisacher
You're actually calling the read2() function from within read2(). This is called recursion, and it is *not* what you want in this case, since it unnecessarily fills up your call stack. Remember that a while loop automatically goes back to the top without you having to re-call your function. I w