Login
|
Signup
langref.org
-
csharp
,
erlang
, and
fsharp
add..
all
clojure
cpp
fantom
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).
fsharp
if name = "Bob" then printfn "Hello, %s!" name
#light
open System
let name = "Bob"
if name = "Bob" then printfn "Hello, %s!" name
fsharp
name = "Bob" && begin printfn "Hello, %s!" name ; true end
#light
open System
let name = "Bob"
name = "Bob" && begin printfn "Hello, %s!" name ; true end
Submit a new solution for
csharp
,
erlang
, or
fsharp
There are 17 other solutions in
additional
languages (
clojure
,
cpp
,
fantom
,
go
...)