This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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: 2367
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
It's not a secret anymore!