wood burning stoves 2.0*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "while loop" Watch "while loop" New topic
Author

while loop

richard stockman
Greenhorn

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.


Thanks.
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: 2367
A local variable has to be initialized by the programmer before you try to use its value.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: while loop