1

I try to create a simple output for definite height of the stairs and I create following code

int spaces = 7;
int sharps = 2;

printf("%i\n", spaces);  // debug
printf("%i\n", sharps);  // debug

for (; spaces <= 0; spaces--)
{
    printf("%i\n", spaces); // debug
}

But when I run this code I just get

7
2

in the output without output from for loop. What I do wrong?

1 Answer 1

1

spaces starts with the value 7, so the condition spaces <= 0 never evaluates to true and your for loop never executes. I think you meant spaces >= 0.

2
  • I got it. I don't know why but I considered this as "to perform the statement until spaces <= 0 is true"
    – algot
    Commented Jul 25, 2016 at 13:38
  • No. Actually the opposite is the case. The loop executes while the condition is true. :) If this answers your question please accept the answer. Happy coding! :)
    – ChrisG
    Commented Jul 25, 2016 at 13:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .