- :-

Topics Covered

  • Repeat Loop
  • Lesson Links

    Check Your Understanding:
    1. 1. What does the repeat structure do?
    2. Repeat the commands between the curly braces " { } "
      Repeat the entire program
      Repeat the first line of command
      Does nothing
    3. 2. How many times does the repeat loop run the commands inside it?
    4. Four times
      Any number of times specified between the curly braces " { } "
      Any number of times specified between the parentheses " ( ) "
      An infinite number of times until told to stop
    5. 3. True / False: The repeat structure ends with a semicolon.
    6. True - Like any other command, the repeat structure must end with a semi-colon
      False - There is no semi-colon for the repeat structure
    Try It!
    Try it! 1

    Whitespace

    Does it matter whether you put the opening brace on its own line or not?

    Try keeping the first opening curly brace " { " on the same line as the repeat command, then run it.

    Try it!

    What Happens?
    The program runs as if nothing has changed. However, it is highly recommended to use the whitespace as a way to organize long programs. Programming etiquettes and clean coding can help navigate long programs much easier.

    Practicing good programming etiquettes also transfer over to other programming languages. Not all programming languages share the same commands and structures, but clean coding carry over can make learning new languages easier.
    Try it! 2

    Sequence of Computer Programming

    In programming terms, the repeat structure is called a “loop”. In computer programming, a loop is a sequence of instructions that is continually repeated until a certain condition is reached. In this example, the condition is repeat four times.

    When the repeat structure has repeated itself four times the condition is met.

    In loops, a certain process is done, such as moving forward and turning, and then some condition is checked such as whether a counter has reached a prescribed number and then the loop is finished and the program moves to the next behavior in its sequence.

    • Change the number of attempts and see what happens to your program.

    • Put additional commands above and below the repeat loop.

    • Replace the number inside of the loop with the word 'forever'

    Try it!

    What Happens?
    Changing the number of attempts will cause the repeat structure to loop that number of times.

    Placing additional commands above the loop will run that command first, then the loop. Anything underneath the loop will run after the loop completes its run.

    Replacing the number inside the loop with "forever" will cause the loop to run in an infinite loop.
    Did You Know?

    Did you know?

    Whitespace

    Whitespace is the location between keywords and symbols in the text-based language.

    Did you know?

    Semicolons and Structures

    Notice that some commands have semi-colons and other do not.

    Semicolons are used to denote the end of a command or statement in ROBOTC.

    Looping Structure, such as the repeat loop, do not have a semicolon on the defining statement of the loop.

    Did you know?

    Behaviors (aka Decompositions)

    A key programming concept is called decomposition. In robotics we call this breaking the robot’s movements into behaviors.

    Repeat Loops - Mini Challenges

    Mini Challenge 1: Circle Maze

    This challenge features a sequence of turns that the robot must perform in order to travel through the maze twice. The robot must first begin at the starting point and get to the goal area by completing turn and forward movement behaviors.

    Fastest Robot Wins, but wheels cannot cross the distance lines completely or else the robot will be disqualified.
    • On a table, recreate the maze shown below and have the robot travel from the start (1), all the way through the maze and back to the start (1).

    Mini Challenge PDF[Circle Maze.pdf ]

    Mini Challenge 2: Circle Maze Rewind

    This challenge features a sequence of turns that the robot must perform in order to travel through the maze twice. The robot must first begin at the starting point and get to the goal area by completing turn and forward movement behaviors.

    The robot must travel the path specified below. The robot must NOT cross any lines.

    However, this time the robot must travel counter-clockwise through the maze.
    • On a table, recreate the maze shown below and have the robot travel from the start (1), all the way through the maze and back to the start (1), but this time in reverse.

    Mini Challenge PDF[Circle Maze Rewind.pdf ]