Pravin R Panicker<br />SCJP,SCWCD
Originally posted by Pravin Panicker:
First run :
i = 2
while (b=!b) Here b is assigned !false ie true
So it will loop again
Second run
i = 3
while (b=!b) Now b is assigned !true ie false
Therefore while exits
So you get i = 3
And System.out.println will print true
----------------------<br />regards.<br /><a href="http://www.mantrotech.com/editors/gaurav_mantro.asp" target="_blank" rel="nofollow">Gaurav Mantro</a><br /><a href="http://www.mantrotech.com/technology/java/index.asp" target="_blank" rel="nofollow">Java Information Portal</a> - <a href="http://www.mantrotech.com/technology/java/index.asp" target="_blank" rel="nofollow">http://java.mantrotech.com</a>
Lee Clarke - SCJP
----------------------<br />regards.<br /><a href="http://www.mantrotech.com/editors/gaurav_mantro.asp" target="_blank" rel="nofollow">Gaurav Mantro</a><br /><a href="http://www.mantrotech.com/technology/java/index.asp" target="_blank" rel="nofollow">Java Information Portal</a> - <a href="http://www.mantrotech.com/technology/java/index.asp" target="_blank" rel="nofollow">http://java.mantrotech.com</a>
case 1. while( (b=!a) )
case 2. while( (b==!a))
In case 1 the result of inner expression (b=!a), should be true if b can be assigned value of !a.
In case 2 the result of inner expression (b==!a), should be true if b is equal to !a.
So what I am trying to say is how does while(b=!a) treated in java?
Does it assign the value to b and check whether b is true or false?
OR
It checks whether the expression (b=!a) was true or not, I mean if there was a condition say (b>a) where b=5 and a is 3 will it return true?
I am a C/C++ background, and I think in C/C++ statement
like while(a=5) will put it in infinite loop.
Lee Clarke - SCJP
----------------------<br />regards.<br /><a href="http://www.mantrotech.com/editors/gaurav_mantro.asp" target="_blank" rel="nofollow">Gaurav Mantro</a><br /><a href="http://www.mantrotech.com/technology/java/index.asp" target="_blank" rel="nofollow">Java Information Portal</a> - <a href="http://www.mantrotech.com/technology/java/index.asp" target="_blank" rel="nofollow">http://java.mantrotech.com</a>
Lee Clarke - SCJP
I love a woman who dresses in stainless steel ... and carries tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|