Login
|
Signup
langref.org
-
python
,
clojure
,
erlang
, and
fantom
add..
all
cpp
csharp
fsharp
go
groovy
haskell
java
ocaml
perl
php
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Structure
Conditionals
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.
python
if name == 'Bob':
print 'Hello, Bob!'
if name == 'Bob':
print 'Hello, Bob!'
clojure
(def person "Bob")
(if (= person "Bob")
(println "Hello, Bob!"))
(def person "Bob")
(if (= person "Bob")
(println "Hello, Bob!"))
erlang
if (Name == "Bob") -> io:format("Hello, ~s!~n", [Name]) ; true -> false end.
-module(ifthen).
-export([start/0]).
start() ->
Name = "Bob",
if (Name == "Bob") -> io:format("Hello, ~s!~n", [Name]) ; true -> false end.
erlang
case Name of "Bob" -> io:format("Hello, ~s!~n", [Name]) ; _ -> false end.
-module(ifthen).
-export([start/0]).
start() ->
Name = "Bob",
case Name of "Bob" -> io:format("Hello, ~s!~n", [Name]) ; _ -> false end.
erlang
Name == "Bob" andalso (begin io:format("Hello, ~s!~n", [Name]), true end).
-module(ifthen).
-export([start/0]).
start() ->
Name = "Bob",
Name == "Bob" andalso (begin io:format("Hello, ~s!~n", [Name]), true end).
fantom
if (name=="Bob") echo("Hello, Bob!")
class SolutionXX
{
Void main()
{
if (name=="Bob") echo("Hello, Bob!")
}
}
Submit a new solution for
python
,
clojure
,
erlang
, or
fantom
There are 17 other solutions in
additional
languages (
cpp
,
csharp
,
fsharp
,
go
...)