Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes Loops Conditionals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Loops Conditionals" Watch "Loops Conditionals" New topic

Loops Conditionals

Landon Blake
Ranch Hand

Joined: Dec 04, 2003
Posts: 121
Can you test more than one conditional in the same loop statement?
Igor Ko
Ranch Hand

Joined: Jun 24, 2002
Posts: 90

You can use any boolean expression.
(there aren't limits to usage variables in such expressions)
Other example:

[ January 08, 2004: Message edited by: Igor Ko ]
[ edited to turn off smilies, which were interfering with the code display -ds ]
[ January 08, 2004: Message edited by: Dirk Schreckmann ]
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

You can, but you also need to be careful. remember that with the && and || operators, as soon as the statement can be determined, it stops looking at the other parts...
also, just because you CAN do something, doesn't mean you should do something...
i've seen IF conditions with upwards of 12 terms, nested 4 or 5 parens deep.
this is EXTREMELY HARD to write, and even worse, harder to debug 6 months down the road.
if you can break up your tests at all, debugging is so much simpler.

note: there are better ways to do this, but this works ok.
[ January 08, 2004: Message edited by: fred rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: Loops Conditionals
It's not a secret anymore!