aspose file tools
The moose likes Beginning Java and the fly likes boolean comparisons Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "boolean comparisons" Watch "boolean comparisons" New topic
Author

boolean comparisons

kelly ball
Greenhorn

Joined: Jan 14, 2004
Posts: 4
Hi
I tried a line of code to compare a boolean value

and the loops I was using for comparisons would not work. I later tried

and it worked
we use Bluej at college and I can't see why but is this in conflict in some way ?
would appreciate any comments
kelly
[ January 24, 2004: Message edited by: Marilyn de Queiroz ]
[ January 25, 2004: Message edited by: kelly ball ]
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
You might want to post a little bit more code here in order for us to help, cause i don't see any reason at all why it should not work.


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9033
    
  10
Are you sure that you didn't type

if (x = true)

by mistake?


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
For that matter, you could also just use
if (x)
As for the original question, see if you can replicate the problem, and post the exact code that demonstrates it. Otherwise I think Marilyn has the right idea about what happened.


"I'm not back." - Bill Harding, Twister
kelly ball
Greenhorn

Joined: Jan 14, 2004
Posts: 4
hi - thanks for your help on this so far
a mis-type " = " for " == ", would be a very simple explanation, but I don't think I did
have reviewed an earlier example I was working on and this is a little more of the code to put it in context

here I was using " nameExists " and it is clearly " = = "
this line when changed to

and it worked [I still had a problem with the loops testing but at least I got the conditional 'if' statement working
regards kelly
thanks for your efforts, but I am still baffled
just reviewing this post - the line about 3 above the 'if test' - is this causing my problem? kelly
[ January 25, 2004: Message edited by: kelly ball ]
Ram Mohan
Ranch Hand

Joined: Jan 19, 2004
Posts: 44
i'm also baffled with regard to this mystery....One question though, why do you have a break statement in your if-condition??? Adds complexity to the code!
since if(nameExists!=false) works, its value is being changed to something else...(probably null)
[ January 25, 2004: Message edited by: Ram Mohan ]

If quitters never win, and winners never cheat, who's the idiot that said: Quit while you're ahead?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
If you change "nameExists != false" back to "nameExists == true" does the problem recur? If not, perhaps something else was going on, like maybe the program wasn't compiled correctly and you were executing an old class file which did not correspond to the latest .java file you were looking at?
As for the break, well this is exactly the sort of situation where I probably would use a break as shown - but with a better comment. I can't tell what "stop here in branch" means. How about "// found name, so exit while loop"? But for the question about a break in a while loop, different people have different opinions on this. I'd say if you do it, it's important that the surrounding code be as clear as possible, since some people who read your code will automatically regard the break as "complex".
Actually the biggest problem I see with this code is that the indentation is horrible. Need to be able to see the loop structure clearly, and there is never any reason for tolerating bad indentation in code. Making your program readable will make all other taks easier.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: boolean comparisons
 
Similar Threads
Array Question
Please drop some comments to improve this program
JScrollPane and paint
Question mark in Java
Is forward slash / a reserverd character?