Is this a bug? boolean opposite evaluation inside for loop

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)

if isTrue == False: continue

Click edit > highlight your code > click the preformatted text button. So we can read your code with more clarity.

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.

Edit: First result on Google: Python break and continue

1 Like

Thanks so much for the clarification. Much appreciated.

i is only ever == 1 in the above loops. Look at the docs for range().

3 Likes

Good point. I was all focused on continue.

Just cause I my self had to look it up.