One name. Many numbered slots. That's an array β the tidiest way to hold a row of the same thing on an Omron controller. Let's fill a box of donuts and watch the variables behave.
The messy way π©
Ten separate variables. Want to loop over them? You can't. Want an eleventh? Add another line by hand. This doesn't scale.
The array way β¨
donuts : ARRAY[0..9] OF BOOL;
One declaration. A box of 10 numbered slots, indices 0 to 9. Reach any slot by its number: donuts[3]. Loop over all of them with a FOR loop. That's the whole idea.
π‘ Sysmac note: Omron NJ/NX arrays start at index 0 by default β so ARRAY[0..9] gives you exactly 10 slots. You can pick any range you like ([1..10], [-5..5]), but 0-based is the house style.
Click a slot to select it, then store a donut or clear it. The Structured Text on the right is exactly what you'd type in Sysmac Studio to do the same thing.
Live Structured Text
// click a slotβ¦
The index in the square brackets is just a number β and it can be a variable. That's the superpower: change i and the same line of code reaches a different slot.
β οΈ Reach past the end β say donuts[10] β and Sysmac Studio flags an out-of-range access. The box has slots 0..9; there is no slot 10.
count := 0; FOR i := 0 TO 9 DO IF donuts[i] THEN count := count + 1; END_IF; END_FOR;
One loop walks every slot, no matter how big the box. Run it against the box you filled above:
In donuts : ARRAY[0..9] OF BOOL; β how many slots, and what's the last valid index?