View Problem

Perform an action if a condition is true (IF .. THEN)

Given a variable name, if the value is "Bob", display the string "Hello, Bob!". Perform no action if the name is not equal.
DiskEdit
ruby
if (name=='Bob')
puts "Hello, Bob!"
end
DiskEdit
ruby
puts "Hello, Bob!" if name=='Bob'
ExpandDiskEdit
java
if (name.equals("Bob")) {
System.out.println("Hello, Bob!");
}
DiskEdit
perl
if ($name eq "Bob") {
print "Hello, Bob!"
}
DiskEdit
perl
print "Hello, Bob!" if $name eq "Bob";
DiskEdit
groovy
if (name=='Bob')
println "Hello, Bob!"
ExpandDiskEdit
scala
val name = "Bob"
if (name.equals("Bob")) printf("Hello, %s!\n", name)
ExpandDiskEdit
scala
val name = "Bob"

// Scala supports operator overloading, so the following works correctly
if (name == "Bob") printf("Hello, %s!\n", name)
DiskEdit
python
if name == 'Bob':
print 'Hello, Bob!'
ExpandDiskEdit
cpp C++/CLI .NET 2.0
if (name == "Bob") Console::WriteLine("Hello, {0}!", name);
ExpandDiskEdit
cpp
if (name == "Bob") std::cout << "Hello, " << name << "!" << std::endl;
ExpandDiskEdit
fsharp
if name = "Bob" then printfn "Hello, %s!" name
ExpandDiskEdit
fsharp
name = "Bob" && begin printfn "Hello, %s!" name ; true end
ExpandDiskEdit
erlang
if (Name == "Bob") -> io:format("Hello, ~s!~n", [Name]) ; true -> false end.
ExpandDiskEdit
erlang
case Name of "Bob" -> io:format("Hello, ~s!~n", [Name]) ; _ -> false end.
ExpandDiskEdit
erlang
Name == "Bob" andalso (begin io:format("Hello, ~s!~n", [Name]), true end).
DiskEdit
ocaml
if name = "Bob"
then print_string "Hello, Bob!"
DiskEdit
csharp
if (name == "Bob") Console.WriteLine("Hello, {0}!", name);
ExpandDiskEdit
php
if($name == "Bob") {
echo "Hello, Bob!";
}
DiskEdit
haskell
name = "Bob"
main = if name == "Bob" then putStrLn "Hello, Bob!" else return ()
DiskEdit
clojure
(def person "Bob")
(if (= person "Bob")
(println "Hello, Bob!"))
ExpandDiskEdit
fantom
if (name=="Bob") echo("Hello, Bob!")
ExpandDiskEdit
go
if name == "Bob" {
fmt.Println("Hello", name)
}

Submit a new solution for ruby, java, perl, groovy ...