MicroBlocks iterator needs a directional argument

Issue #152 resolved
David Talmage created an issue

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)

  1. John Maloney repo owner

    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:

  2. Log in to comment