(Oct-26-2016, 06:23 AM)diemildefreude Wrote: Ah, I think I see the problem. the last print is not related to the loop, so it's processed as an error if you enter it in the ... at the end of the loop statement. But in a script, it's perceived as a new statement.Yes this is is correct shell(interactive interpreter) execute line by line or a block in one go.
Therefor will the print statement at end of while block give syntax error.
In a script it will work fine.
i = 1 while i <= 6: print 2 * i, ' ', i += 1 print 'aaaaaaaaa'
Output:2 4 6 8 10 12 aaaaaaaaa
As a new user in Python you should be thinking of starting with Python 3 it's the future.Same script and end='' is clearer than just a comma for prevents a new line to be emitted.
i = 1 while i <= 6: print(2 * i, end= ' ') i += 1 print('aaaaaaaaa')
Output:2 4 6 8 10 12 aaaaaaaaa