如果值不为零,则打印一个值 [英] print a value if it is not zero

查看:107
本文介绍了如果值不为零,则打印一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果值超过零,我需要打印出一个值:

I need to print out a value if it is above zero:

info({mail, BoxPid, Messages, MessageCount, MessageDropCount}, Req, S) ->
    if MessageDropCount > 0 ->
            io:format("dropped=~p~n", [MessageDropCount]);
       true -> true
    end,
    ...,
    {loop, Req, S};

我不喜欢 true - >如果表达式,则为的一部分。有办法避免吗?有没有一个成语?

I do not like the true -> true part of the if expression. Is there a way to avoid it? Is there an idiom for that?

推荐答案

如果在ErlangCentral维基上的Then页面建议这些模式:

The If Then page at the ErlangCentral wiki suggests these patterns:


  • [io:format(dropped =〜p〜n,[MessageDropCount])|| MessageDropCount> 0]

  • MessageDropCount> 0 andalso io:format(dropped =〜p〜n,[MessageDropCount])

  • MessageDropCount = 0 orelse io:format(dropped =〜p〜n,[MessageDropCount])

  • [io:format("dropped=~p~n", [MessageDropCount]) || MessageDropCount > 0]
  • MessageDropCount > 0 andalso io:format("dropped=~p~n", [MessageDropCount])
  • MessageDropCount =< 0 orelse io:format("dropped=~p~n", [MessageDropCount])

这篇关于如果值不为零,则打印一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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