top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

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

+1 vote
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
  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?

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.