Is there a simpler way to check multiple values against one value in an if-statement?

前端 未结 12 916
名媛妹妹
名媛妹妹 2020-11-27 07:55

Basically, what I want to do is check two integers against a given value, therefore, classically what you would do is something like this:

//just to get some         


        
12条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 08:22

    For this example, you can do

    if (a * b == 0)
    

    or for more variables

    if (a * b * c * d == 0)
    

    while more concise it may not be as clear. For larger values, you need to cast to a long to avoid an overflow.

提交回复
热议问题