While you're at it (Python) While loops


#1

# Hi,this is my code -
num = 1

while num < 11:
 return num
  num ** 2
print num
  # And this is the error i'm getting -

File “python”, line 4
SyntaxError: ‘return’ outside function

#I have attempted to update my indentation in all the places possible, but still no luck.Any help please?

#2

This is not an indentation error, this is a usage error. You have used a return statement in an improper manner. A return statement can only be placed within a function. Since while is a loop and not a function, you cannot utilize return statements with it.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.