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"}"
ExpandDiskEdit
cpp C++/CLI .NET 2.0
if (age > 42) Console::WriteLine("You are old");
else Console::WriteLine("You are young");
ExpandDiskEdit
cpp C++/CLI .NET 2.0
Console::WriteLine("You are {0}", (age > 42 ? "old" : "young"));
ExpandDiskEdit
cpp
std::printf("You are %s\n", (age > 42 ? "old" : "young"));
ExpandDiskEdit
fsharp
if age > 42 then printfn "You are old" else printfn "You are young"
ExpandDiskEdit
fsharp
let message = if age > 42 then "old" else "young"
printfn "You are %s" message
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
csharp
int age = 41;

if (age > 42)

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



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