0

Till what number will y decrement and why.? In case of Java it is saying cannot convert from int to boolean.! Why is that.?

Working perfectly in c++ int x=1,y=6; while(y--){ x++; }

27th Sep 2020, 4:39 AM
shrijith
shrijith - avatar
6 Antworten
+ 4
Shrijith P.S try something like this in Java. int x=1,y=6; while(y-- > 0){ x++; } System.out.println(x);
27th Sep 2020, 7:07 AM
minirkk
minirkk - avatar
+ 3
Shrijith P.S Good explanation here... (the case in C and C++ are the same here) https://stackoverflow.com/questions/36467523/why-while-loop-differently-work-in-java-and-c
27th Sep 2020, 7:18 AM
minirkk
minirkk - avatar
+ 2
You can't have integer as a condition. There should be boolean, like while(y > x).
27th Sep 2020, 4:54 AM
Aleksandrs
Aleksandrs - avatar
+ 1
C++ is not java, thats why
27th Sep 2020, 5:16 AM
Jeremy
Jeremy - avatar
27th Sep 2020, 5:38 AM
shrijith
shrijith - avatar
0
It works RKK ,but in c++ the code written in description works perfectly
27th Sep 2020, 7:14 AM
shrijith
shrijith - avatar