[erlang-questions] Global Variable

Chandru <>
Mon Feb 25 07:59:21 CET 2008


On 25/02/2008, J Bhanot <> wrote:
>
> Hi,
>
> I simple want to use if-else statements and use data from that to build
> message...
>
> e,g,
>
> if condition = 1then
>
> msg = 1
>
> else
>
> if condition = 2 then
>
> msg = msg + 2
>
> if condition = 3 then
>
> return msg
>
> Basically, i want to build message recursively based upon conditions...i.e.
> msg is my global variable
>
> I just could not find out the way it can be done in erlang

Something like this?

build_msg(Msg, [1 | Conditions]) ->
    build_msg(1, Conditions);
build_msg(Msg, [2 | Conditions]) ->
    build_msg(Msg + 2, Conditions);
build_msg(Msg, [3 | _]) ->
    Msg;
build_msg(Msg, [_ | Conditions]) ->
    build_msg(Msg, Conditions);
build_msg(Msg, []) ->
    Msg.



More information about the erlang-questions mailing list