#include
using namespace std;
int main(int argc, char *argv[])
{
int i=-5;
while(~(i))
{
cout<
You are correct about i == -1 being the exit condition: your loop is equivalent to
int i=-5;
while(i != -1)
{
cout<
When written this way, it should be clear why -1 is not printed the value is first printed, and only then incremented, that's why -2 is the last value that you print.
The ! operator, on the other hand, will produce 1 only when it is given a zero. That's why the loop would print -1 when the ! operator is used in the loop condition.