I have a for loop and within that there is a simple single line if condition. I want to use continue option in the else part.
This does not work :
def defA() : return "yes" flag = False for x in range(4) : value = defA() if flag else continue ^ SyntaxError: invalid syntax Working code :
for x in range(4) : if flag : defA() else : continue
X if C else Yis an expression.continueis a statements. Expressions in Python cannot contain statements. Transform yourifexpression into anifstatement to fix.continue).