Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 large counted loop
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cool dude




PostPosted: Tue Jul 04, 2006 9:00 am   Post subject: large counted loop

if you have to go to a very large number in a counted loop, it will say integer too large. so how would i do that? i tried using BigInteger, but it is not working and i'm not too sure if that is right?
Sponsor
Sponsor
Sponsor
sponsor
r.3volved




PostPosted: Tue Jul 04, 2006 12:10 pm   Post subject: (No subject)

counted loop as in a 'for' loop??

long myNum = 0;
while(myNum != 623456823746L)
{
++myNum;
}


if it's so long that it won't let you do a for loop, then a forloop probably isn't the best aproach
cool dude




PostPosted: Tue Jul 04, 2006 1:26 pm   Post subject: (No subject)

r.3volved wrote:
counted loop as in a 'for' loop??

long myNum = 0;
while(myNum != 623456823746L)
{
++myNum;
}


if it's so long that it won't let you do a for loop, then a forloop probably isn't the best aproach


yes counted loop as a for loop. and i need the for loop.

p.s. why do you have a L at the end of the number?
TheFerret




PostPosted: Tue Jul 04, 2006 1:29 pm   Post subject: (No subject)

You could have a different variable type in the counter if needed, like:

Java:
for(long i=0; i<584846484654; i++) {
}


And that should work...
r.3volved




PostPosted: Tue Jul 04, 2006 2:23 pm   Post subject: (No subject)

L denotes a long integer
Just as if you were to do:

float myNum = 0.0f; //can use 'f' or 'F'


instantiation I guess would be:
long myNum = 0L; //can use 'l' or 'L'


I'd imagine the long would work with no problems in a for loop.
I just tend to avoid for loops that are so long like that and choose another procedure.
Krabjuice




PostPosted: Tue Jul 04, 2006 5:05 pm   Post subject: (No subject)

Java:

for(int i=0; i<...; i++)
{
   if (i=...)
   {
       x+=1;
   }
   else if (x=...)
   {
       break;
   }
}

Replace "..." as necissary.

That should last a good while.
wtd




PostPosted: Tue Jul 04, 2006 5:36 pm   Post subject: (No subject)

Using the assignment operator in a conditional could lead to trouble.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: