15,399,574 members
See more:
C
```#include<stdio.h>
int main ()
{

int i = 5;
while(i-- >=0)

printf("%d,",i);
i = 5;
printf("\n");
while(i-- >=0)
printf("%d,",i);
//break;
while (i-- >=0)
printf("%d,",i);

return 0;
}```

What I have tried:

the output is coming
4,3,2,1,0,-1
4,3,2,1,0,-1

but ..I have coded for i-- >=0 ..so why it is showing till -1.
Posted
Updated 14-May-21 21:01pm
v2

## Solution 1

Have a look at Increment/decrement operators - cppreference.com[^]

As you can see, you have used a post-increment operator so the comparison is done with the original (copied) value but the next line is executed using the decremented value.

## Solution 2

Two things:
1) To add to what Wendelius says, this may help: Why does x = ++x + x++ give me the wrong answer?[^] - it doesn't exactly apply to your code, but it explains what the operators do, which may hep you understand why your code doesn't do what you expected.

If you don't your code becomes mush harder to read, and that means you can make mistakes a lot easier.
C
```#include<stdio.h>
int main ()
{
int i = 5;
while(i-- >=0)
printf("%d,",i);
i = 5;
printf("\n");
while(i-- >=0)
printf("%d,",i);
//break;
while (i-- >=0)
printf("%d,",i);
return 0;
}```
It's also a lot safer to always use curly brackets to delimit blocks:
C
```#include<stdio.h>
int main ()
{
int i = 5;
while(i-- >=0)
{
printf("%d,",i);
}
i = 5;
printf("\n");
while(i-- >=0)
{
printf("%d,",i);
}
//break;
while (i-- >=0)
{
printf("%d,",i);
}
return 0;
}```
v2