frustrating failure of 'break' statement ( novice )

Rhodri James rhodri at wildebst.demon.co.uk
Sun Jun 14 00:15:47 CEST 2009


On Sat, 13 Jun 2009 22:48:43 +0100, <pdlemper at earthlink.net> wrote:

> In my programs the 'break' fails to work.  I've studied the docs for
> 3.0 and Programming in Python, neither of which are illuminating.
> Simplest example :
>
> while True :
>     num = int(input())
>     print(num)
>     if num == 0 :
>         break
>
> print('done')
>
>
> SyntaxError : invalid syntax    ( pointing to end of break )
> This happens whether the 'break' is put on same line as the
> conditional, flush with while, flush with if, or appropriately
> indented 4 spaces.

It works for me, running it from file.  It fails with "invalid
syntax" (pointing to the end of *print*) if I cut and paste
the program exactly into a Python shell, presumably because the
shell gets unhappy about having more command input when it
wants to be executing the while loop.  Does this match what
you see?

-- 
Rhodri James *-* Wildebeest Herder to the Masses



More information about the Python-list mailing list