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
  • LED Lights

LED Lights

How it Works

How the first_list Script Works

  • Watch the animation as it steps through the first_list script and displays variable values and data. (Or view full size with play/pause control: list-how-it-works.mp4.)
  • Pay careful attention to the index values, and how they control which string gets stored by the color variable and displayed.

In the script, clist = [’green’, ’yellow’, ’red’] creates a list with three items: clist[0] is ’green’, clist[1] is ’yellow’, and clist[2] is ’red’.  The value of the index variable starts at zero.  Inside the while True loop, color = clist[index] stores ’green’ in color when index is 0, ’yellow’ in color when index is 1, or ’red’ in color when index is 2.  Each time through the loop, index = index + 1 increases the value of index by 1.  Before repeating the loop, if index >= len(clist) statement compares the value of index to the number of elements in the list.  When index reaches 3, the statement evaluates to true, and index is set back to 0.

Try This: Lists the Easier Way

Yes, there is an easier way!  A for color in clist: loop will automatically copy each successive item in clist into the color variable.  If your script just needs to cycle through items in a list, this is the way to go!

  • Set the project name field and line-1 comment to first_list_try_this.
  • Modify the script as shown below, then click Save.
  • Click Send to micro:bit.

 

  • If the serial monitor isn’t already open, click Show serial.
  • Verify that the output matches the first example.

 


Printer-friendly version
Intro to Lists
Prev
Other Data Types in Lists
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress