This repository was archived by the owner on Oct 23, 2018. It is now read-only.
forked from mishoo/UglifyJS
-
Notifications
You must be signed in to change notification settings - Fork 2
Conditions, loops and switches
dangreen edited this page Jan 2, 2015
·
3 revisions
In ColaScript switch statement may be used without argument:
switch {
when score < 60: 'F';
when score < 70: 'D';
when score < 80: 'C';
when score < 90: 'B';
default: 'A';
}As you see, you can use keyword when, it's like case, but if the condition is satisfied, switch will break'ed.
Also you can use as expression if condition:
String name =
if (sex == "male") "Dan"
else if (sex == "female") "Dasha"
else "none";and switch statement:
String grade = switch {
when score < 60: 'F';
when score < 70: 'D';
when score < 80: 'C';
when score < 90: 'B';
default: 'A';
};Also available ES6 for ...of loop:
for _ of [5...10] {
console.log(_);
}As you can see for (as well as if, while and switch) may used without brackets (also you can use old syntax).