By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,641 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

infinite loop

P: 47
how can we detect an infinite loop in visual basic 6.0 and so dat we can report an error whenever the program enters an infintie loop???
Jul 21 '07 #1
Share this Question
Share on Google+
5 Replies


hariharanmca
100+
P: 1,977
how can we detect an infinite loop in visual basic 6.0 and so dat we can report an error whenever the program enters an infintie loop???

You can use Recursion Function

Private Sub callRecursionFunction()
Statements...............
Statements...............
Statements...............
Statements...............
callRecursionFunction()
Statements...............
Statements...............
Statements...............
End Sub
Jul 21 '07 #2

P: 47
You can use Recursion Function

Private Sub callRecursionFunction()
Statements...............
Statements...............
Statements...............
Statements...............
callRecursionFunction()
Statements...............
Statements...............
Statements...............
End Sub


sry but i cant understand wht u r trying to say. i am asking dat i am using many while loops and for loops in my program however if due sum condition or anything else the loop enters in an infintite loop do i have any way to detect it so dat i can report it to the user that the program has entered in an infintite loop???
Jul 21 '07 #3

Expert 5K+
P: 8,434
sry but i cant understand wht u r trying to say. i am asking dat i am using many while loops and for loops in my program however if due sum condition or anything else the loop enters in an infintite loop do i have any way to detect it so dat i can report it to the user that the program has entered in an infintite loop???
I don't think there is any easy way to catch this kind of thing. After all, a program often has to loop many times. At what point does "many" become "too many"? It would depend on the particular circumstances. In some cases, you may want it to loop "forever".

I suppose you could increment a counter each time around a loop, and clear it after exiting the loop. Keep watching it, and if it gets too large (you'd need to decide just how much is too much) then do your thing.

Probably the simplest way to implement that would be by calling some kind of standard "count these calls and tell me if I've done more than x" function.

By the way, as far as I can see what hariharanmca posted was not a way to detect an infinite loop, but an easy way to create one. Although this would not in fact keep going forever, as it would produce something like a "stack overflow" error after a while.
Jul 22 '07 #4

pureenhanoi
100+
P: 175
how can we detect an infinite loop in visual basic 6.0 and so dat we can report an error whenever the program enters an infintie loop???
All programing language (not only VB) cannot recorgnize infinite loop by them-selft. Never try such a stupid job. Manage ur loop by ur-selft, if u're still a programer.
Jul 23 '07 #5

Expert 5K+
P: 8,434
All programing language (not only VB) cannot recorgnize infinite loop by them-selft. Never try such a stupid job. Manage ur loop by ur-selft, if u're still a programer.
That's what I said. :)

I just used more words. (Plus I was a bit more polite. Hint hint...)
Jul 23 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.