© Pradeeka Seneviratne  2019
Pradeeka SeneviratneBBC micro:bit Recipeshttps://doi.org/10.1007/978-1-4842-4913-0_7

7. Loops and Logic

Pradeeka Seneviratne1 
(1)
Udumulla, Mulleriyawa, Sri Lanka
 
This chapter presents some recipes about how to use loops and logic with MakeCode. MakeCode provides four type of loops to continually repeat blocks until a certain condition is reached:
  • repeat

  • while

  • for

  • for element

It also provides three types of block categories for decision making:
  • conditional

  • comparison

  • Boolean

7-1. Repeating Some Code Blocks Several Times

Problem

You want to display numbers from 1 to 10 using a loop.

Solution

  • In the Toolbox, click the Variables category. Then click on the Make a Variable… button. In the New variable name modal box, type x. Then click ...

Get BBC micro:bit Recipes: Learn Programming with Microsoft MakeCode Blocks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.