18,700
edits
m (lede wording) |
m (→schedule ... repeat ... every ...: copy edit (style consistency)) |
||
Line 671: | Line 671: | ||
schedule dprint("Is this annoying yet?") repeat 50 every 20; | schedule dprint("Is this annoying yet?") repeat 50 every 20; | ||
This | This is basically equivalent to the following "for" loop in a C-style programming language: | ||
for(int i=0; i | for (int i = 0; i < 50; i++) | ||
{ | |||
wait( | print("Is this annoying yet?"); | ||
wait(20); | |||
} | } | ||
To create an infinite loop, you can use "0" or a negative number as the repeat value: | |||
schedule dprint("Is this annoying yet?") repeat 0 every 20; # repeats forever | schedule dprint("Is this annoying yet?") repeat 0 every 20; # repeats forever | ||
"schedule-repeat-every" can be used in place of recursive functions that call themselves ''n'' times using "fork". For example, | |||
func void hey(void) | |||
{ | |||
func void hey(){ | |||
dmsg("hey"); | dmsg("hey"); | ||
sleep(1); | sleep(1); | ||
fork hey(); | fork hey(); | ||
} | } | ||
func void main () { | func void main(void) | ||
{ | |||
fork hey(); | fork hey(); | ||
} | } | ||
Line 699: | Line 699: | ||
can be replaced by: | can be replaced by: | ||
func void hey(){ | func void hey(void) | ||
{ | |||
dmsg("hey"); | dmsg("hey"); | ||
} | } | ||
schedule hey() repeat 0 every 60; | schedule hey() repeat 0 every 60; | ||
Note | Note the significant difference between the built-in "sleep" function, which operates in whole seconds, and the "schedule" commands, which operate in ticks (1/60 of a second). Using "schedule" gives you much greater control over the timing of BSL execution than a "fork"+"sleep" loop would. | ||
==Variables== | ==Variables== |