Skip to main content

Lesson 2: Flow of a Project with a [Repeat] Block

When a project uses a [Repeat] block, it still follows the same logic while executing the commands. These two stacks of blocks will execute the same behaviors. The only difference is that the stack of blocks on the right utilize a [Repeat] block.

Two stacks of blocks. The first stack on the left shows 8 blocks. From top to bottom they read drive forward for 600 millimeters, turn right for 90 degrees, drive forward for 600 millimeters, turn right for 90 degrees, drive forward for 600 millimeters, turn right for 90 degrees, drive forward for 600 millimeters, and turn right for 90 degrees. The stack on the right shows a repeat loop set to repeat 4 times with two blocks inside. The blocks inside read drive forward for 600 millimeters and turn right for 90 degrees.

The VR Robot will move through the commands from the [When Started] block to the bottom of the stack. The [Repeat] block indicates that the VR Robot should repeat the actions inside of the block the specified number of times before moving on to the next block in the stack after the [Repeat] block.

The specified number of times that the [Repeat] block is set to execute creates a ‘condition.’ Conditions allow the user to control the flow of a project. The condition of the [Repeat] block must be met before the project will move on to the next block in the stack. The condition created in the following example is to ‘repeat the [Drive for] and [Turn for] commands four times.’ 

Two stacks of blocks are shown. The stack on the left has a when started block with six blocks attached. From top to bottom, the blocks read move robot pen down, repeat 4. Inside the repeat 4 loop two blocks are shown: drive forward for 600 millimeters and turn right for 90 degrees. Below the repeat loop is two final blocks that read set robot pen color to red and drive reverse for 600 millimeters. To the right, the same stack of blocks is shown but with red arrows to denote how the robot will move through the project. The arrows move sequentially down the blocks then shown that the repeat loop will have the drive forward and turn right commands inside repeat in order 4 times before moving to set the pen color red and drive in reverse.

Mini Challenge

In this project, the VR Robot should draw a blue square on the Art Canvas Playground, but there are errors in the project. Edit the project to solve the mini challenge!

Art Canvas Playground in VEXcode VR with a blue square drawn to the top right of the VR robot.

Follow these steps to complete the mini challenge:

  • The robot starts in the middle of the playground and draws the four sides of a large blue square.
  • Modify the Unit3Lesson2 project to match this image. Remember that you can use VEXcode blocks, Switch blocks, or a combination of both block types with a VR Premium account. 

    Stack of blocks in VEXcode VR. The when started block has 6 blocks attached that read as follows from top to bottom. Move pen down, set pen color to red, drive forward for 600 millimeters, repeat 3. Inside of the repeat 3 are two blocks that read drive forward for 600 millimeters and turn right for 90 degrees.

  • Start the project and identify where the VR Robot does not complete the expected behaviors.
  • Modify the project and run the project again. See if the VR Robot completes the expected behaviors.
  • If the VR Robot does not draw a blue square, repeat the previous step and try again. Continue to modify and run your project until the VR Robot draws a blue square.
  • Once the VR Robot successfully draws a blue square on the Art Canvas Playground, save the project.

Congratulations! You solved the mini challenge!

Questions

Please select a link below to access the lesson quiz.

Google Doc / .docx / .pdf