Yours is not a correct syntax for the ForEach/Next loop. This form of iteration allows us to access each element in an array without referring to any particular index within the array or the array bounds per se. In this way, we are able to avoid creating implicitly any unwanted elements if the array happens to be a dynamic array. dict is a dynamic array (in fact, every FBSL text split function returns one) and we'd better use unindexed iteration to be on the safe side.

OTOH the inner loop does need an index to calculate the power, which yields the following resultant code:

- Code: Select all
`FOREACH DIM num IN dict`

IF ABS(num) < 100 THEN

display(num, "is too small")

ELSE

FOR DIM j = 9 DOWNTO 1

IF ABS >= 10 ^ j THEN

IF j MOD 2 = 1 THEN

display(num, "has even number of digits")

ELSE

display(num, middle3(ABS, j))

END IF

EXIT FOR

END IF

NEXT

END IF

NEXT

The use of ForEach/Next and volatile ABS permits us to:

1. avoid referencing an array element through its index which is a time-costly operation in any language, whereas here the element is automatically buffered in the "num" variable;

2. reduce the count of temporary number variables to just one "num" by buffering the temporary absolute value in the ABS() function's own volatile.

Also, the middle3() function can be safely reduced to:

- Code: Select all
`FUNCTION middle3(n, pwr)`

DIM m = (n \ (10 ^ (pwr \ 2 - 1))) MOD 1000

IF m = 0 THEN RETURN "000"

RETURN m

END FUNCTION

All this will make our code a few temporary variables and lines shorter and also faster.

And finally, to me "geek" sounds more like "ill with" which doesn't necessarily mean "master in". When combined, "geek" and "master" yield a "guru".