There are no tracking or monitoring cookies on this site. There are only cookies used for documentation examples related to cookies.
Close

Processing...
This may take a few seconds.

@while

Syntax

(event selector:event) {
(...)
@while expr {
(...)
(target selector) {
(...)
@while expr {
(action commands)
}
(...)
}
(...)
}
(...)
}

expr (expression) = This can include JavaScript syntax, ACSS conditionals or a mixture of both. See the examples below for possible syntax choice and to see how ACSS conditionals and JavaScript can be used together. The expression should result in boolean "true". JavaScript "anonymous" functions are not allowed in the expression. Curly braces that are not surrounding variables are not permitted in the expression.

The @while statement can wrap around target selectors and action commands.

The @while command performs a loop of its inner contents while the expression passes. When the expression now longer equates to boolean "true", the @while loop breaks out. The @while loop will also break out if the selector to which it is attached is no longer on the page.

Use @while if you are using delayed events or using the pause command, and need a loop to continue indefinitely on the page, or until the target element surrounding the @while statement removed.

If you want to crash your browser, you can do this easily by setting up an infinite loop like "@while true { ... }" and have no "pause" command, or break, exit or exit-target commands. You probably won't ever want to do this, so when handling the @while loop bear in mind that care needs to be taken so that you don't accidentally set up an infinite loop.

 

There now follows examples of possible uses of the @while statement, including use of the break, continue, exit and exit-target control flow commands.

@while - basic use

@while - continue

continue puts the control flow immediately back to the top of the loop.

@while - break

break puts the control flow immediately after the loop (it breaks out of the loop).

@while - exit

exit breaks out of the whole event. Nothing else in the event will run.

@while - exit-target

exit-target breaks out of all actions inside the target selector.