Exit a While Loop?

Hello Guys…
Is it possible to exit a loop if the initial conditions isn’t met?
meaning if the while loop looks like this:

while( (value 1.state as DecimalType < value2.state as DecimalType))

and i wanna exit it before the above statement is true with a switch?

I don’t understand the question.

But a while loop can have || and && clauses like any if statement so do you mean something like this?

var boolean exitFlag = false
while( (value1.state as DecimalType < value2.state as DecimalType) && !exitFlag) {
    ...
    if(some condition) {
        exitFlag = true
    }
}
1 Like

Thanks… exactly what I needed… in my plc world I need to do something like if … then exit…
thanks :slight_smile:

Sorry for the dumb question - but what is the ll? Or?

Yes, || means a logical or, there’s usually a place for the vertical bar “|” (aka a “pipe”) on the keyboard but if you own one from one of the few countries that don’t have it, then you can hold alt and press 124 on the keypad to get it.