I was working with some boolean values inside a for loop and was getting the opposite effect of what I was expecting. Can anyone show me where I may have a mistake in what I think I understand with the logic below? Much appreciated for any help.
Note: I think this may be the same in Python as well (outside of Ignition)
isTrue = True
#case 1: not working
for i in range(1, 2):
if isTrue: continue
print('if isTrue: continue')
#case 2: not working
for i in range(1, 2):
if isTrue == True: continue
print('if isTrue == True: continue')
#case 3: working in reverse (True = False)
for i in range(1, 2):
if isTrue == False: continue
print('if isTrue == False: continue')
#output from above tests (only the 3rd case fell into a print statement)
isTrue = True
#case 1: not working
for i in range(1, 2):
if isTrue: continue
print(‘if isTrue: continue’)
#case 2: not working
for i in range(1, 2):
if isTrue == True: continue
print(‘if isTrue == True: continue’)
#case 3: working in reverse (True = False)
for i in range(1, 2):
if isTrue == False: continue
print(‘if isTrue == False: continue’)
Assuming this is how your code is formatted, it’s working as intended. The continue statement ceases the current loop’s iteration and goes on to the next iteration of the loop. As isTrue is always True, your print statements aren’t being executed. If you remove the continue statement for either case 1 or 2 they will work as you wish.