Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If condition

 
asha ganapathy
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please let me know where i am going wrong
In my opinion the x value should be 2, but the answer is 4.
 
aslika bahini
Ranch Hand
Posts: 111
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi asha,



else if(b=false){ // yes b is false here
x=2;

orginally posted by asha

here.. you are assigning b=false.

if, b == false then, it prints x = 2

regards
samura

 
Praveen Seluka
Ranch Hand
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

The second condition
else if (b=false) is an assignment operation.It assigns b to false and then the if loop becomes false so it wont be x=2.

Thanks
Praveen SP
 
asha ganapathy
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i got it thanks a lot
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic