What does “Comparing constant with boolean expression is always true” warning mean?

前端 未结 3 2013
死守一世寂寞
死守一世寂寞 2020-12-20 01:15

What does this warning mean (i and j are not constants):

I have been trying to Google this but it does not give me any results.

3条回答
  •  独厮守ぢ
    2020-12-20 01:35

    The other answers have already explained the core problem. You can use:

    if ( ( ( 0 <= i) && (i <= 10)) && ( ( 0 <= i) && (i <= 10)) ) 
    

    to resolve your problem.

    My recommendation will be to wrap that logic in a function.

    int isInRange(int x, int lower, int upper)
    {
       return (lower <= x && x <= upper);
    }
    

    and use

    if ( isInRange(i, 0, 10) && isInRange(j, 0, 10) )
    

提交回复
热议问题