-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontrol_flow.erl
More file actions
71 lines (56 loc) · 1.65 KB
/
control_flow.erl
File metadata and controls
71 lines (56 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
%%%-------------------------------------------------------------------
%%% @author Chris Duesing <chris.duesing@gmail.com>
%%% @copyright (C) 2010, Chris Duesing
%%% @doc
%%%
%%% @end
%%% Created : 18 Apr 2010 by Chris Duesing <chris.duesing@gmail.com>
%%%-------------------------------------------------------------------
-module(control_flow).
%% API
-export([simple_case_statement/0, case_statement/1, simple_function/0, case_function/1, start_print_loop/0]).
%%%===================================================================
%%% API
%%%===================================================================
%%--------------------------------------------------------------------
%% @doc
%% @spec
%% @end
%%--------------------------------------------------------------------
simple_case_statement() ->
X = "Joe",
case X of
"Chris" ->
io:format("Hey Chris!~n");
SomeoneElse when is_list(X) ->
io:format("Hey, ~s have you Seen Chris?~n", [SomeoneElse]);
_ ->
error
end.
case_statement(X) ->
case X of
"Chris" ->
io:format("Hey Chris!~n");
SomeoneElse when is_list(SomeoneElse) ->
io:format("Hey, ~s have you Seen Chris?~n", [SomeoneElse]);
_ ->
error
end.
simple_function() ->
X = 5,
Y = 4,
X + Y.
case_function("Chris") ->
io:format("Hey Chris!~n");
case_function(SomeoneElse) when is_list(SomeoneElse) ->
io:format("Hey, ~s have you Seen Chris?~n", [SomeoneElse]);
case_function(_) ->
error.
start_print_loop() ->
X = [1, 2, 3],
print_loop(X).
print_loop([H | T]) ->
io:format("printing ~p~n", [H]),
print_loop(T);
print_loop([]) ->
io:format("finished printing.~n").