This page has no translation to 한국어 yet. The original English version is below. If you’d like to help, great! See how to translate a documentation page in the contribution guide.
Note This is a web-version of a tutorial chapter embedded right into the XOD IDE. To get a better learning experience we recommend to install the desktop IDE or start the browser-based IDE, and you’ll see the same tutorial there.

Loops

Screenshot of 205-loops

Let’s make a simple traffic light. Each light is activated by the delay node. When the latest one finishes it sends a pulse to the begining and our traffic light starts over.

To make the loop we need a special defer node. When defer node receives some value or pulse it postpones downstream nodes evaluation until the next transaction.

The defer node is always required when you make a loop to avoid deadlocks. For now, you can remember to place defer nodes right in the places where you want to complete a feedback loop. Read the guide to better understand the execution model.

Program begins with the initial boot pulse. Then each delay node triggers the next one. The latest one pulses back to the beginning, and it works continuously.

Exercise #

Let’s bring the button back and make the device start with the button press.

  1. Assemble a circuit according to the scheme.
  2. Replace boot with the button node and bind the corresponding PORT value.
  3. Link with a free pin of the any node.
  4. Upload the program.

Press the button to run the chain.

Found a typo or mistake? Want to improve the text? Edit this page on GitHub and open a pull request. If you have a complex proposal or you want to discuss the content, feel free to start a new thread on XOD forum.