Results 1 to 8 of 8
Thread: while(true)
- 12-03-2007, 11:48 AM #1
Senior Member
- Join Date
- Nov 2007
- Posts
- 115
- Rep Power
- 0
- 12-03-2007, 01:33 PM #2
Member
- Join Date
- Nov 2007
- Posts
- 18
- Rep Power
- 0
Inside the loop there will be some conditions to come out of it(break;)
It is to execute some statements continuously unless and until some conditions reached.
- 12-03-2007, 02:36 PM #3
Member
- Join Date
- Nov 2007
- Posts
- 25
- Rep Power
- 0
- 12-03-2007, 05:16 PM #4
Senior Member
- Join Date
- Nov 2007
- Posts
- 115
- Rep Power
- 0
Ok kool. So a break statement is a must if we use while(true). Otherwise it wont terminate.
- 12-03-2007, 08:34 PM #5
Member
- Join Date
- Nov 2007
- Posts
- 8
- Rep Power
- 0
not necessary a break statement but you need something inside the loop that alters the condition for it to exit.
e.g.
a=5;
while (a < 10)
{
System.out.println("A is " + a);
a++
}
This will print out something like:
A is 5
A is 6
A is 7
A is 8
A is 9
and then when a has reached 10, the condition is no longer true so it will break out of the loop. if you had
a=5
while(a<10)
{
System.out.println("A is " + a);
}
will be stuck in a continual loop because there is nothing inside it to alter the state of a. The program will just keep printing 'A is 5' an infinite amouint of times.
A is 5
A is 5
A is 5
A is 5
A is 5
A is 5
A is 5
A is 5
A is 5........forever.
Hope thats helped.
- 12-04-2007, 09:43 AM #6
Senior Member
- Join Date
- Nov 2007
- Posts
- 115
- Rep Power
- 0
Thanks mate.
I got the point.
- 06-28-2011, 11:43 PM #7
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Annas, please don't resurrect threads that are 4 years old.
- 06-29-2011, 06:05 AM #8
Similar Threads
-
bug (?) in ProcessBuilder.redirectErrorStream(true);
By gadasie in forum Advanced JavaReplies: 3Last Post: 03-13-2008, 09:04 AM -
setVisible(true) does not work
By Gajesh Tripathi in forum AWT / SwingReplies: 2Last Post: 10-27-2007, 07:32 PM


LinkBack URL
About LinkBacks


Bookmarks