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


DiskEdit
clojure clojure
(def age 41)
(if (> age 42) "You are old" "You are 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"));

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