top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Why while(x--) does not work in Java, while it works in C/C++?

+1 vote
438 views
Why while(x--) does not work in Java, while it works in C/C++?
posted Feb 16, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

In short it is because of strict type checking in Java. In Java conditional statement expects only boolean inside them and as x-- can be any integer which will not be boolean that is why it is not allowed in Java.

Correct usage would be while(x-- > 0) instead while(x--)

answer Feb 17, 2016 by Salil Agrawal
Similar Questions
–1 vote
while(i<10);
{
  i++;
  printf("%d,\n", i);
}

Loop does not run for 10 iterations, what is the error?

+3 votes

In Java
I am using statement a += b where a is int and b is double, when I use a += b, it won't give error but in case of a = a + b it gives error, why ?

0 votes

While compiling step by step if we don't include -o while generating 1.i it will not create a new file and write the output on stdout, but in case of generating 1.s/1.o if we don't write -o it is automatically creates a new file and writes data into it. Why?

...