Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / December 2005

Tip: Looking for answers? Try searching our database.

while loops

Thread view: 
vicki - 08 Dec 2005 16:15 GMT
set number to 3
while (number is 3 or more)
     write out number
     increase number by 1
write "finished"

i would if some one can help me how many loop body will be executed with the
way i look at it in's an infinitive loop. the number starts at three andit
will always be 3 or more.
vicki

Signature

v davies

David Kerber - 08 Dec 2005 16:35 GMT
> set number to 3
> while (number is 3 or more)
[quoted text clipped - 5 lines]
> way i look at it in's an infinitive loop. the number starts at three andit
> will always be 3 or more.

In mathematics, yes, but in the computer world that will only be true
until it rolls over past the max value of the variable type holding the
loop index.

Signature

Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).

Hiran Chaudhuri - 08 Dec 2005 21:22 GMT
> set number to 3
> while (number is 3 or more)
[quoted text clipped - 7 lines]
> will always be 3 or more.
> vicki

That one heavily depends on the interpreter for this language.
There will probably be a datatype that can take an arbitrary number of
digits. And depending on the interpreter you might see an overflow if the
number gets 'max_number+1'. Then it might either be negative and the loop
terminates, or you might see an exception or error message. Depending on the
number of digits your data type 'number' has, you can wait pretty long......

Hiran
Roedy Green - 08 Dec 2005 23:30 GMT
>set number to 3
>while (number is 3 or more)
[quoted text clipped - 6 lines]
>will always be 3 or more.
>vicki

This is trick question. Write the loop and run it, and to your suprise
the loop will eventually stop, because of he way integers wrap around
to negative after they get too big.  Try adding 1 to Integer.MAX_VALUE
to see what I mean.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.