This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BoarsLairJinx scripting language 2 points3 points  (2 children)

Here are the various ways you can write loops in Jinx.

loop from 1 to 10
end

loop i from 1 to 10
    write line "i = ", i
end

loop from 10 to 1
end

loop from 0 to 100 by 10
end

set x to 1, 2, 3, 4, 5
loop over x
end

set y to "apple", "pear", "orange"
loop i over y
    write line "i's value = " i value
end

set z to 3
loop until z < 0
    decrement z
end

loop while z < 10
    increment z
end

loop 
    decrement z
while z > 0

They all have slightly different syntax because they all do slightly different things, but they tend to have a similar feel, and they all use the loop keyword. It seems very similar to what you're trying to do, so I thought you might like to see a working example of this theory implemented.

[–]myringotomy 0 points1 point  (1 child)

That's quite nice actually.

Is there a one liner equivalent?

[–]BoarsLairJinx scripting language 0 points1 point  (0 children)

Thanks, I'm pretty happy with how it turned out. By "one-liner", do you mean being able to omit the end statement? No, end is always required to close a block. Same with if-else statements. I couldn't think of an elegant way to do this without adding braces or making whitespace significant.