Tip #2 - Counter Checking

This tip is from Soulbain, who wanted to point out what follows:

Many times we are faced with a scenario where we need to check a counter for a whole range of values, and do something different depending on what value is present. In this case, one might do the following:
...
...
if "counter" = 1 "label1"
if "counter" = 2 "label2"
if "counter" = 3 "label3"
if "counter" = 4 "label4"
if "counter" = 5 "label5"
...
...

In this scenario, doing so is a waste of time and robot memory. The above code can be replaced with:
...
...
goto "label&counter&"
...
...
in which case you simply name your labels according to the value of the counter. Remember that if there is no label for the counter value, (e.g. "counter" equals 7 and there is no "label7" present, the code will "fall through" and will simply go onto the next line.

Back to the tips page.
1