This is an example of how to use recursion as a loop in a program. The program will call a task called flash_user_led and once there the task calls itself 10 times resulting in the USER LED flashing random colors.
Once the LED has flashed 10 times the skipout command is called and the program will end.
Program
---
Flash USER LED using a recursive task.
---
prog_vars =
d/color 0
d/flash_count 0
prog_vars.
prog_start =
pclear
print "Recursive flash program."
prog_start.
prog_loop =
flash_user_led 5
exitprog
prog_loop.
flash_user_led /start_count 0 =
-- Get a new random color
rand 0 15 -> /color
-- Set USER LED to the color
l1 /color
"Flash no /flash_count color /color start /start_count"
inc /flash_count
-- Check if we should stop
any /flash_count >= 10 ->
"Time to Stop"
skipout
enda.
-- Recursively call again
flash_user_led 8
"ERROR WE SHOULD NOT BE HERE"
flash_user_led.
prog_stop =
print "Exit Twinkle"
prog_stop.