-2
int i;
for(i=10;i<=20;i=i+2)
    if(i%10 <= 5)
        printf("hello\n");

Why is "hello" printed four times? I expected it to be three times. Is it because of precedence?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578

1 Answers1

2

Pay attention to the loop exit condition, which is <= rather than the more common <. The printout is triggered for i values of 10, 12, 14, and also 20.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578