如何在Erlang中使C样式的if-else语句等效? [英] How to make the equivalent of a C-style if-else statement in Erlang?

查看:59
本文介绍了如何在Erlang中使C样式的if-else语句等效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何等效于 C风格 if-

 if(a == b) {
   expression1
 } else {
   expression2 
 }


推荐答案

if
    a == b ->
        expr1;
    true ->
        exprElse
end

Erlang中没有别的,您只需匹配与真实。有关详细信息,请参见 Erlang文档

There is no real else in Erlang, you just match with true. More information at the Erlang documentation.

您必须密切注意';'终止符:

You have to pay close attention to the ';' terminator :

if
    a == b ->
        clauseN,
        expr1;
    cond2 ->
        clause1,
        clause2,
        expr2;
    cond3 ->
        expr3;
    true ->
        exprElse
end 

这不是复制粘贴友好的语言。

It's not a copy-paste friendly language.

这篇关于如何在Erlang中使C样式的if-else语句等效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆