Noob question: Loop instead of nested IF

Hi for now I always use nested if-statements like:


Can I instead use some form of loop formular to improve myself?

In the example shown, it looks like you could just divide show_counter by 10 and that would handle all the scenarios you are doing in your ‘if’.

If you’re just doing a bunch of lookups, if A then X, if B then Y, if C, then Z, I tend to use app or page variables (with type object) to create “lookup variables”. The “key” is the looked-up element, the “value” is the returned value.

  'A': 'red',
  'B': 'yellow',
  'C': 'blue'

Then use LOOKUP(‘A’) which will return ‘red’. This has an advantage of containing your mapping values outside of the app logic itself - so if you want to change a label, or color assignment, etc, you don’t have to go into the app logic, you just edit your lookup variable.

Here I have a lookup called “pressure needle” which takes a weather trend label (retrieved from an external api call) and converts it to a rotation angle for an animated compass needle:

if I LOOKUP(‘rising’), I get 0, if I LOOKUP(‘steady’) I get 90, and LOOKUP(‘falling’) returns 180…all compass degrees.

The IF/ELSE version of this would be:

IF(label ==‘rising’,0,IF(label==‘falling’,90),IF(label==‘steady’),180,NULL)))

1 Like

thanks for the answer. this helps me alot