Erlang equivalent to if else

前端 未结 4 661
傲寒
傲寒 2020-12-16 14:59

I have 2 parts of code I want to execute. Both are conditionals

if Value1 < N do something 

else if Value1 >= N do something

if Value2 < N do some         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-16 15:43

    Erlang doesn't allow you to have an if without a true statement option. Whether or not this is something that is a true statement or an actual true is up to you, but it is commonplace to have your true be the else in other languages.

    if 
        some_condition -> some_code;
        some_other_condition -> some_other_code;
        true -> else_code
    end.
    

    See the "What the If?" section on this page for more on this.

提交回复
热议问题