Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-27-2007, 04:33 AM
Member
 
Join Date: Apr 2007
Location: Pennsylvania,USA
Posts: 46
sandor is on a distinguished road
eternal loop problem
why is this loop not stopping?
Code:
public static final int END = Integer.MAX_VALUE; public static final int START = END - 100; public static void main(String[] args) { int count = 0; for (int i = START; i <= END; i++) count++; System.out.println(count); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-27-2007, 04:24 PM
Member
 
Join Date: Apr 2007
Location: Indiana
Posts: 84
pegitha is on a distinguished road
Send a message via Skype™ to pegitha
All int variables are always less tha or equal to Integer.MAX_VALUE, which is defined as the highest int value. When i gets to Integer.MAX_VALUE andi s incremented, it silently wraps around to Integer.MIN_VALUE, thus the eternal loop.
p
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-27-2007, 05:57 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Quote:
All int variables are always less tha or equal to Integer.MAX_VALUE, which is defined as the highest int value. When i gets to Integer.MAX_VALUE andi s incremented, it silently wraps around to Integer.MIN_VALUE, thus the eternal loop.

Hmm.. You are right. Congratulation pegitha, you are careful.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-29-2007, 04:55 PM
Member
 
Join Date: Apr 2007
Location: Pennsylvania,USA
Posts: 46
sandor is on a distinguished road
Thanks for that info. There is an awful lot I need to learn.
sandor
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
do...while loop eva New To Java 16 01-31-2008 07:44 AM
For loop problem mcal New To Java 32 01-25-2008 04:51 PM
A loop that doesn't loop MichYer New To Java 2 07-30-2007 09:44 AM
While loop leebee New To Java 1 07-18-2007 04:11 PM
Loop Help HeavyD New To Java 5 07-10-2007 02:26 PM


All times are GMT +3. The time now is 10:44 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org