Nested Events

Control structures that are placed inside other control structures; for example, loops occurring inside other loops, or a conditional statement being evaluated inside a loop.

In the above example, we can code the bee to collect all the nectar using simple sequencing of the movement blocks, but the code is inefficient.

If we add a single loop for the repeated movements on each side of the square we can shorten the code dramatically.

If we add a nested loop (a loop inside a loop) for all of the repeated 'move forward" and "get nectar" blocks we can make the same code even more efficient. The video below shows how to create nested loops. This example corresponds with Mathematics Grade 4 C3.1, C1.1, and E1.1

Grade 4 - Nested Events.mp4

Try it now!

To practice with nested events, access this sample activity from Course D of studio.code.org ⤵️