Hallo 1unitedpower,
- Ruby:
x = if condition then foo else bar end- Haskell:
x = if condition then foo else bar- Rust:
x = if condition { foo } else { bar }- Python:
x = foo if condition else bar- Elm:
x = if condition then foo else bar- PureScript:
x = if condition then foo else bar- OCaml:
x = if condition then foo else bar- F#:
x = if condition then foo else bar- …
Elixir treibt es hier übrigens auf die Spitze: if ist hier nur ein Makro, dass zu einer Funktion umgeschrieben wird; if cond do … end wird im AST zu if(cond, fn -> … end) (vereinfacht).
Übrigens hat @Tabellenkalk schon recht, das ist alles abgeguckt von LISP, der Mutter aller Programmiersprachen 😀 dort ist if ein special operator, der die Form (if condition then-form [else-form]) hat. Der Rückgabewert ist hier der Rückgabewert der Then-Form bzw der Else-Form, je nach Ergebnis von condition. Gibt es keine Else-Form aber die condition gibt false zurück, wird nil zurück gegeben.
LG,
CK