GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes while(true) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "while(true)" Watch "while(true)" New topic
Author

while(true)

Phillipe Rodrigues
Ranch Hand

Joined: Oct 30, 2007
Posts: 165
I want to know the line no(1) execution. What the (1) check. What is the other way we can specify line no (1)



Thanks,
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

A while(true) loop is an infinite loop - the loop never terminates (at least, not until you stop the program).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Phillipe Rodrigues
Ranch Hand

Joined: Oct 30, 2007
Posts: 165
How can I write the line(1) using the If condition?
Nickolas Case
Ranch Hand

Joined: Apr 26, 2008
Posts: 98
Set a boolean method and test on that.


Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

Originally posted by Phillipe Rodrigues:
How can I write the line(1) using the If condition?

You cannot, because if is not a looping construct like while.

You could do this trick with for, but I don't recommend it, because it's more unreadable than the version with while:

[ June 04, 2008: Message edited by: Jesper Young ]
Phillipe Rodrigues
Ranch Hand

Joined: Oct 30, 2007
Posts: 165
while(true) means ?

is it saying while the run() is getting executed or what while(true) checks.when the while condition executes?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Originally posted by Phillipe Rodrigues:
while(true) means ?


It just literally means that as long as true == true, the loop will continue. Since true is always equal to true, it means "loop forever."


[Jess in Action][AskingGoodQuestions]
 
wood burning stoves
 
subject: while(true)