![]() |
for / else not working in interactive mode - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: for / else not working in interactive mode (/thread-19839.html) |
for / else not working in interactive mode - Skaperen - Jul-17-2019 this little test script works: however, doing the same exact thing interactively gets a syntax error: any idea what is wrong?
RE: for / else not working in interactive mode - ichabod801 - Jul-17-2019 The interactive interpreter wants you to end the for loop with a blank line before continuing on with more code:
RE: for / else not working in interactive mode - Skaperen - Jul-17-2019 that doesn't work, either:
RE: for / else not working in interactive mode - stranac - Jul-17-2019 The end of a for/else is after the else block:>>> a=[1,2,3,4,5,6] >>> b=[0,5,10] >>> for x in b: ... if x in a: ... print('foo') ... break ... else: ... print('bar') ... foo >>> print('xyzzy') xyzzy RE: for / else not working in interactive mode - Skaperen - Jul-17-2019 why does the interactive interpreter use a different syntax than the script interpreter? |