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

前端 未结 3 2011
死守一世寂寞
死守一世寂寞 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:54

    I believe you need to understand what's going on in your statement at a deeper level.

    0<=i is a boolean expression, it will become true or false. The result of that expression is then compared with 10.

    So you end up with true <= 10 or false <= 10.

    I think you meant to write

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

    You cannot connect clauses together the way you did.

提交回复
热议问题