As the question asks, why doesn\'t the below code work:
while True:
exec(\"break\")
I am executing the above in pycharm via python 3.
exec
is a built in function ,
Python insists that break
should happen inside the loop,not inside a function
What is happening in your code is you are putting break
inside a function
which is exec
you can't break out of a loop by executing a
break
within a function that's called inside the loop.
For Ex
>>> def func():
break
SyntaxError: 'break' outside loop
>>>