• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2 Basic java questions. While loops and...

 
Ben Cramphorn
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, what is wrong with the followingpiece of code??



When I run my program it keeps on getting stuck in a loop.

Secondly is there a command which allows me to clear all the text on a screen and move my and move my cursor back to the top of the screen???

Thanks alot....
 
Ben Cramphorn
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meh I figured it out.. I needed to put & instead or OR... my bad...
 
Ben Baker
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't your uni's name down as well ..... FY(N)
 
Ben Cramphorn
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who Be You?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben,

You should also consider using && and || instead of & and |. The difference is that && and || can "short circuit" the evaluation as soon as it discovers what the result must be. As an example, if you have an expression (x && y) and x evaluates as false, then y is never even evaluated. Similarly for the expression (x || y) evaluates x as true, then y is not evaluated.

Keep coding!

Layne
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some of us old timers have the advantage (?) of coming from a COBOL background. The language lets you leave out certain repetitious parts of the syntax for brevity:

Of course humans say "if a not 1 or 2 or 3" so we coded it wrong about half the time - exactly as you did. After a few thousand errors - stare at the code for a day and not see why it doesn't work - we all learn to stop and look at these things twice before going on. So welcome aboard! If you learned to stop and examine any "and" and "or" code on the first error you're way ahead!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic