Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-14-2002, 03:33 PM   #1 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
the endless loop loop loop loop loop loop ...

just thought id share a pretty basic thing that i came up with while getting stuck in many-a-endless loop.

Code:
int goneToFar = 0;
boolean mainLoopSetter = true;

while(mainLoopSetter || goneToFar > 100)
{
 //do whatever to set mainLoop false
goneToFar++; //this added to exit out if the other doesn't get set
}
its pretty simple, and i've only used it once, but not only does it stop from crashing your computer and very quickly running out of memory but it may even force you to see the problem for the loop before you even test it...


--EDIT--
oops.. changed to OR and greater then
--EDIT--
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Old 08-14-2002, 03:40 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,705
redhead is on a distinguished road
Well, there is one time, where it will exit.
when mainLoopSetter is true, and goneToFar reaches 100.
But if the condition says, at a point where goneToFar is 99, set goneToFar+=2, then it will run forever.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 08-14-2002, 03:43 PM   #3 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
erm, wtf, i totally stuffed that up

anyhow... the idea is add an extra little thing (goneToFar) just to count up and end the loop if the other value doesn't get set somewhere else, heh, woops.
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Reply

Bookmarks

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

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



All times are GMT -8. The time now is 01:30 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting