Till what number will y decrement and why.? In case of Java it is saying cannot convert from int to boolean.! Why is that.? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 Answers
+ 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
Rohit
+ 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
Rohit
+ 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