The problem is the line containing the while. Because you have a semicolon at the end of the line, that statement is the complete while loop. It is essentially a no-op delay loop. When using a short, it comletes after 256 iterations and the print statement is executed.
When used with an int or long, it appears to hang because the while will take a while to complete before the print statement is executed.
Remember, Java executes the next statement after the while. In your case, you've coded a null statement by placing the semicolon right after the while. Java looks at the semicolons - the indenting is just to make it easier for us to read it. Java ignores whitespace.
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
As Tom pointed out, your while loop (as shown) doesn't do anything because it's followed immediately by a semicolon.
If you remove the semicolon (and assuming that you want to increment t rather than y), it will execute an iteration for each value greater than 1 within the variable type range -- at which point the value "overflows" to a negative and fails the test. For wider types, this might appear infinite at first, but the loop will end if you give it time.
Try changing the type of t in the following code...
[ May 23, 2005: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Large positive numbers "wrap around" to large negative ones. If you add one to Integer.MAX_VALUE (the largest positive int value) you get Integer.MIN_VALUE (the largest negative int value.) The binary numeral for the largest int is a zero followed by 32 ones:
add one to this, and the value overflows, and you get
which is the largest negative int. If you keep adding one, eventually you get