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
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]).
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"));

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