arohner/scriptjure

document 'while'

sneilan opened this issue · 4 comments

This is a slight problem. There's no way to create a loop at the moment. For now, I'll just use the quote operator:

user=> (js (quote "while (1) {") (alert "asdf") (quote "}"))
"while (1) {;\nalert("asdf");\n};\n"

while already works, but is apparently not documented.

OK, I'll see if maybe I can write some documentation for that.

Oh wow! You're right, it does work. A while loop has the same syntax as any other function, therefore you can go like this:
(js (while (== a 5) (alert "asdf!")))
Which will print
"while ((a == 5)) { \nalert("asdf");\n\n }"

Definitely can't write for loops without the quote operator though:
user=> (js (for (var i 5) (<= i 5) (++ i)))
"var i;\nfor(i = 5;\n, (i <= 5), i++)"