A loop in Forth with an ending value of SORTSLOTS and a starting value of 0 will cover an entire inventory.
The loop stops before executing the last iteration, so on a regular 27-slot chest, the loop goes from 0 to 26, which is fine. The slots are zero-based to a Sortron so there is no slot 27.
What if I want to loop in reverse? If I do this:
...the loop executes on slot -1! How come the end value is inclusive on negative loops?
Code:
SORTSLOTS 0 ?DO
...
LOOP
What if I want to loop in reverse? If I do this:
Code:
-1 SORTSLOTS 1 - ?DO
...
-1 +LOOP