Syntactic Sugar

GoMelan supports different kind of syntactic sugar (shorter ways of writing the same code).

List of supported syntax

  • var++ and var += 1 -> add 1 to var

  • var-- and var -= 1 -> substract 1 from var

  • for (<variable-declaration> ; <condition> ; <variable-update>) for loop simplification

fn main() -> Bool
{
    a: Float = 0.5;
    
    for (i: Float = 0.0; i <= a; i += 0.1) {
        if (i > a) {
            return false;
        }
    }
    return true;
}

Output:

true
  1. Declare one Float variable.

  2. Loop while i is lower or equal to a.

  3. If there is no problem, the code returns True and otherwise False.

Last updated