I have a multiple line if statement used to filter out a series of constraints. I would like to know if there is a function to exit the if statement if a condition is met without running through the whole statement.
Eg
IF Condition A then
X = 0
ELSIF Condition B then
X = 1
ELSIF Condition C then
X = 0
ELSE
X=1
ENDIF
In the example above assume there is an overlap between Condition A and B.
If the code runs on this overlap, then X is set to 0 as it fulfils Condition A but is then set back to 1 as it fulfils Condition B
I would like to know if there is a way to exit the statement as soon as the condition is set to 0, without it moving through the whole IF statement ?
Hi!
In ProBuilder, the structure IF ... ELSIF ... ELSE ... ENDIF is specifically designed to stop evaluating as soon as one condition is met. That means, if Condition A is true, the subsequent conditions (Condition B, C, etc.) are not evaluated at all.
So, the behavior you’re describing, where X gets reassigned after meeting Condition A,should not happen if you’re using a proper ELSIF chain.
Here you have an example:
1
2
3
4
5
6
7
8
ema=average[50](close)
ifclose>emathen
count1=1+count1
elsifclosecrosses overemathen
count2=1+count2
endif
returncount1,count2
Count2 will always be 0.
If you use to if endif then it will be different:
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok