spam=0
while spam < 1000:
spam = spam+1
if spam == 900 or 990:
continue
print('spam is ' + str(spam+ 1))
else:
print('done')
you have a while/else
, which means else
runs when while condition evaluate to false. The else doesn’t run when the loop is broken using break
keyword
this comparison:
if spam == 900 or 990:
always evaluate to true, given python will simply evaluate 990 as true, given it isn’t compared to anything.
this is the inspiration for a programming joke:
A wife sends her programmer husband to the grocery store for a loaf of bread, On his way out she says “and if they have eggs, get a dozen”. The programmer husband returns home with 12 loaves of bread…
this is literally how computers thing (and thus the programmer thinks, given he need to write instructions to the computer), you need to compare at both side of the or
operator
1 Like