0
Guys ...the program always tell me 'break' outside loop ,how do I fix this..still a beginner
3 ответов
+ 4
Because of the intendations. Your if statement does not belong to your while loop.
Here is a solution:
name = ''
while name != 'joe':
print('enter correct name')
name = input()
if name == 'joe':
break
print('hi user')
+ 2
The indentation is wrong. In Python blocks are defined via equal indentation.
In this case the break is not even necessary as the check before is the same as for the loop itself.
+ 1
Your indents prior to your break place the break outside the while loop.
Remember, a break is used inside a loop, so your indents must be within the loop