Is there an easy way to tell if 'ANY' numeric table elements are 'TRUE' or '1'


I’m looking for a straightforward way (probably OptoScript) to scan through a numeric table and spit out a Boolean or an integer if ANY of the elements in that table are non-zero (i.e., TRUE). Is the best way to go about this just iterating over the entire table with a FOR loop, or is there a simpler path?


Not sure how long your table is or how often you need to test for a “true” bit, but a For/Next loop in OptoScript is probably your best bet.


You don’t need to iterate over the entire table since you could break out as soon as you find a non-zero value. Since Opto doesn’t have a break statement on for loops, a while or repeat loop would be more efficient. This would probably be a good case for a subroutine.

nLength = GetLengthOfTable(MyTable);
i = 0;

until(MyBool or i>=nLength);


Thanks all! I sort of figured this would be the route. And thanks for the tip Philip.