File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes while loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "while loop" Watch "while loop" New topic

while loop

richard stockman

Joined: Apr 11, 2006
Posts: 11
When trying a simple while loop is it correct that it will not work unless any variables are actually given a value rather then just delaring them as ints.
eg - This will not compile.

Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
If a primitive is not initialized, it has no value, therefore it can not be compared, so a compiler error makes sense.

As an aside an easier way to do that without loops is n(n+1)/2.
[ April 23, 2006: Message edited by: Rusty Shackleford ]

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
A local variable has to be initialized by the programmer before you try to use its value.
I agree. Here's the link:
subject: while loop
jQuery in Action, 3rd edition