Login
|
Signup
langref.org
-
csharp
,
erlang
, and
clojure
add..
all
cpp
fantom
fsharp
go
groovy
haskell
java
ocaml
perl
php
python
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.
csharp
if (name == "Bob") Console.WriteLine("Hello, {0}!", name);
if (name == "Bob") Console.WriteLine("Hello, {0}!", name);
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).
clojure
(def person "Bob")
(if (= person "Bob")
(println "Hello, Bob!"))
(def person "Bob")
(if (= person "Bob")
(println "Hello, Bob!"))
Submit a new solution for
csharp
,
erlang
, or
clojure
There are 18 other solutions in
additional
languages (
cpp
,
fantom
,
fsharp
,
go
...)