[erlang-questions] separators before end

Doug Edmunds <>
Wed Sep 19 20:44:42 CEST 2007


Use of semicolons seems workable with IF as well
(but look closely at the final IF expression, where
there is a semicolon already).

From: doc/getting_started/seq_prog.html

% original
test_if(A, B) ->
    if
        A == 5 ->
            io:format("A = 5~n", []),
            a_equals_5;
        B == 6 ->
            io:format("B = 6~n", []),
            b_equals_6;
        A == 2, B == 3 ->                      %i.e. A equals 2 and B equals
3
            io:format("A == 2, B == 3~n", []),
            a_equals_2_b_equals_3;
        A == 1 ; B == 7 ->                     %i.e. A equals 1 or B equals
7
            io:format("A == 1 ; B == 7~n", []),
            a_equals_1_or_b_equals_7
    end.



%With a semicolon before expressions, this becomes

test_if(A, B) ->
    if
       ; A == 5 ->
            io:format("A = 5~n", []),
            a_equals_5
       ; B == 6 ->
            io:format("B = 6~n", []),
            b_equals_6
       ; A == 2, B == 3 ->                      %i.e. A equals 2 and B
equals 3
            io:format("A == 2, B == 3~n", []),
            a_equals_2_b_equals_3
       ; A == 1 ; B == 7 ->                     %i.e. A equals 1 or B equals
7
            io:format("A == 1 ; B == 7~n", []),
            a_equals_1_or_b_equals_7
    end.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070919/e5495240/attachment.html>


More information about the erlang-questions mailing list