for loop - statement with no effect

前端 未结 5 450
一整个雨季
一整个雨季 2021-01-28 06:36

For some reason I\'m getting an error: statement with no effect on this statement.

for (j = idx; j < iter; j + increment) {
    printf(\"from lo         


        
相关标签:
5条回答
  • 2021-01-28 06:57

    Replace

    j + increment
    

    With

    j += increment
    
    0 讨论(0)
  • 2021-01-28 07:00

    You probably meant to write j += increment instead of j + increment.

    0 讨论(0)
  • 2021-01-28 07:02

    You are getting that as an error? How cool, I wish my compiler did that. Basically j + increment will return the sum of those two, but j won't get modified so your loop would probably run forever.

    0 讨论(0)
  • 2021-01-28 07:06

    It's clear you meant +=, but in the case that isn't true, the 'volatile' qualifier should prevent warnings.

    0 讨论(0)
  • 2021-01-28 07:09

    I think you meant j += increment, as j + increment doesn't actually alter j or indeed have any side effects at all - it is a statement with no effect, which is what the compiler is telling you

    0 讨论(0)
提交回复
热议问题