[erlang-questions] is there "return" in Erlang.

黃耀賢 (Yau-Hsien Huang) g9414002.pccu.edu.tw@REDACTED
Mon Feb 28 04:59:11 CET 2011


getA(), getB(), doSomeThing(...), and doThings() are other functions to be
implemented.

if structure is provided in Erlang:

   if
        test ->  calculation ;
        test ->  calculation ;
        ...
        test -> calculation
   end

It need not write `return' in Erlang. A function returns a value by the last
statement/
clause in a function.

In general, `void judge()' has a structure like:

    judge() ->
       A = getA(),
       B = getB(),
       if
            A == CONF1 -> doSomeThing(A) ;
            B == CONF2 -> doSomeThing(B) ;
            true -> doThings()
       end.


2011/2/28 Wang Wei <wgwi@REDACTED>

> Hello, I has a question about how to convert the bellow C program into
> Erlang.
>
> void judge()
> {
>    int a;
>    int b;
>
>    a = getA();
>    if (a == CONF1)
>   {
>       doSomeThing(a);
>       return;
>   }
>
>   b = getB();
>   if (b == CONF2)
>   {
>       doOtherThing(b);
>        return;
>   }
>
>   doThings();
>   return;
> }
>
> I think about "case" and "if" construct, but none of it seems work fine,
> thanks for help.




-- 

Best Regards.

--- Y-H. H.


More information about the erlang-questions mailing list