Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Simple BlocklyProp Programs for Propeller Boards

Simple BlocklyProp Programs for Propeller Boards

Blocks that Repeat

Sometimes you need to be able to program your Propeller to repeat certain operations. This ability is useful for simple things, such as blinking  light, and more complex tasks, such as robotic sensor navigation.

Blocks of repeating code are called loops.  A loop can be set up to repeat a set of blocks forever, or while a defined condition is true, or for a specified number of times.

 

Test Code

Open a new project and build the blocks as shown.  You can find the conditional repeat block under the CONTROL menu.

  • Make sure the BlocklyProp client is running, and your board is selected.
  • Load to RAM.
  • The terminal will open.  After a few seconds, it should look like this:

The program above first prints the text “This loop repeats forever,” and then moves the cursor to the next line.  Then, the program sets up a loop.  Inside the loop, there is a block that prints the text “…and ever…” with a new line and a 1-second pause.  The program will continue running forever.  The only way to stop the program is to reset the Propeller microcontroller.

 

Try This – Break

Many programs need to use loops that run forever, but sometimes it is helpful to break out of a loop. That is where the break block comes in handy. 

In the next example, we will set up a new variable and give it a value of 0.  Inside of the loop, we will add 1 to the variable using the de/increment block from the VALUES > NUMBERS  menu. We will set it to increment, which is just a fancy way of saying “add 1 to the variable.”  Then, we will use an if…do block to see if our variable is greater than 5, and if it is, break out of the loop.

Modify your program to look like this:

  • Make sure the BlocklyProp client is running, and your board is selected.
  • Load to RAM.
  • The Terminal will open.  After a few seconds, it should look like this:

 

Try This – Conditional Repeat

The conditional repeat block has some additional options:

  • Try simplifying your program by using one of the options in the conditional repeat block instead of using if…do and break.
  • Try asking the user how many times to repeat using the Terminal receive number block.

Try This – Counted Loops

Sometimes, it is helpful for your loop to skip-count.  Imagine that you need to turn a motor all the way around, but you want to stop every ten degrees – the repeat item block lets you do just that:

Now, try building a program that skip-counts:

  • Open a new project and build the blocks as shown:

  • Make sure the BlocklyProp client is running, and your board’s COM port is selected.
  • Load to RAM.
  • The Terminal will open and begin counting to 100 by 10’s.

 

Your Turn – Counted Loops

You can use the repeat item block to count down as well.  When you change the “by” value in the block, and start with a higher number than you end with, the repeat item block will count down (decrement) instead of up.

  • Modify your program to countdown.
  • Try creating a program that first counts up and then counts down.

Printer-friendly version
Make Complex Decisions
Prev
Graphing Data
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress