View Problem

Perform different actions depending on a boolean condition (IF .. THEN .. ELSE)

Given a variable age, if the value is greater than 42 display "You are old", otherwise display "You are young"
DiskEdit
ruby
if (age > 42)
puts "You are old"
else
puts "You are young"
end
DiskEdit
ruby
puts (age>42) ? "You are old" : "You are young"
DiskEdit
ruby
puts "You are #{age > 42 ? "old" : "young"}"
DiskEdit
csharp
int age = 41;

if (age > 42)

System.Console.WriteLine("You are old");
else
System.Console.WriteLine("You are young");


ExpandDiskEdit
erlang
if Age > 42 -> io:format("You are old~n") ; true -> io:format("You are young~n") end.
ExpandDiskEdit
erlang
Message = if Age > 42 -> "old" ; true -> "young" end, io:format("You are ~s~n", [Message]).
ExpandDiskEdit
erlang
case Age > 42 of true -> io:format("You are old~n") ; false -> io:format("You are young~n") end.
ExpandDiskEdit
erlang
case Age of _ when Age > 42 -> io:format("You are old~n") ; _ -> io:format("You are young~n") end.
ExpandDiskEdit
erlang
Message = case Age of _ when Age > 42 -> "old" ; _ -> "young" end, io:format("You are ~s~n", [Message]).
ExpandDiskEdit
erlang
Age > 42 andalso (begin io:format("You are old~n"), true end) orelse (begin io:format("You are young~n"), true end).
ExpandDiskEdit
erlang
(fun (X) when X > 42 -> io:format("You are old~n"); (_) -> io:format("You are young~n") end)(Age).
ExpandDiskEdit
erlang
(fun () when Age > 42 -> io:format("You are old~n"); () -> io:format("You are young~n") end)().
ExpandDiskEdit
erlang
io:format("You are ~s~n", [if Age > 42 -> "old" ; true -> "young" end]).
DiskEdit
clojure clojure
(def age 41)
(if (> age 42) "You are old" "You are young")

Submit a new solution for ruby, csharp, erlang, or clojure
There are 21 other solutions in additional languages (cpp, fantom, fsharp, groovy ...)