Login
|
Signup
langref.org
-
erlang
add..
all
clojure
cpp
csharp
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.
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).
Submit a new solution for
erlang
There are 19 other solutions in
additional
languages (
clojure
,
cpp
,
csharp
,
fantom
...)