ternary_operator.gravity 299 B

1234567891011121314151617
  1. #unittest {
  2. name: "Ternary operator.";
  3. error: NONE;
  4. result: "le1le1eq2eq3ge4ge4";
  5. }
  6. func test(x) {
  7. return x <= 2 ? x == 2 ? "eq2" : "le1" : x >= 4 ? "ge4" : "eq3";
  8. }
  9. func main() {
  10. var result = "";
  11. for(var i in 0...5) {
  12. result += test(i);
  13. }
  14. return result;
  15. }