Skip to content

[Enhancement] conditional expression - #284

Open
khchen wants to merge 1 commit into
ThakeeNathees:masterfrom
khchen:exprif
Open

[Enhancement] conditional expression#284
khchen wants to merge 1 commit into
ThakeeNathees:masterfrom
khchen:exprif

Conversation

@khchen

@khchen khchen commented Jul 30, 2022

Copy link
Copy Markdown

In many other language, ternary operator (:?) is the syntax for basic conditional expression.
However, in some language (e.g. coffeescript), they use if expression as conditional expression.

This patch adds if expression as the conditional expressionf for pocketlang.
I think it is more clear than ternary operator especially there is more then one condition (if ... elif ... else ...).

In the if expression, than can be omit, and end is not necessary (aslo not allowed). Example:

print(if true then 123 else 456)
print(if true 123 else 456)
print(if false 123 elif false 546 else 789)

a = if false
      123
    elif false
      456
    else
      789

print(a)

Output:

123
123
789
789

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant