MicroBlocks iterator needs a directional argument
MicroBlocks for X in Y
needs a directional argument so that it can traverse a collection from first to last or from last to first. As it exists now, for X in Y
traverses a collection from first to last.
My use case is lighting a sequence of LEDs on the BBC micro:bit. I use a list of triples <x, y, duration> to describe the LED sequence. I want to be able to play the sequence both forwards and backwards. For example, to light a row of LEDs one at a time from left to right and back. For short sequences, it suffices to create two lists, one from left to right and one from right to left. It is tedious and difficult to do that for longer sequences. On small-memory devices like the micro:bit, using two lists might severely limit the length of the sequence.
Comments (2)
-
repo owner -
repo owner - changed status to resolved
Hope the explanation helped...
- Log in to comment
The MicroBlocks for loop is simple by design, to make it more accessible to beginners. However, you can get the effect you want with indexing and a bit of arithmetic. Here’s an example: