Stops any running Timed Loops, or a specific one if passed in return value of timedLoop()
.
Some Timed Loops do not run forever, but need to be stopped at some time (maybe like a countdown, see the first example). stopTimedLoop()
allows you to stop timed loops from running, either from within the loop itself or elsewhere in your program.
Stop a timed countdown once it reaches 0
var countdown = 10; textLabel("countdown", countdown); timedLoop(1000, function() { countdown = countdown - 1; setText("countdown", countdown); if(countdown === 0) { stopTimedLoop(); } });
Run a half second timed loop until a button is pressed.
// Run a half second timed loop until a button is pressed. button("stop", "Stop the timer"); timedLoop(500, function() { console.log("Timer code ran!"); }); onEvent("stop", "click", function(){ stopTimedLoop(); });
stopTimedLoop(loop);
Name | Type | Required? | Description |
---|---|---|---|
loop | Number | The value returned by the `timedLoop()` function that you want stop. If not included, all running timed loops will stop. |
timedLoop()
, eg `var i = timedLoop(ms, callback);Found a bug in the documentation? Let us know at documentation@code.org