![]() |
Public Function primechk(max As Integer)
I'm still writing the prime number algorithm and so far I have this code for my function: :
Dim primes() As Integer:
For index = 0 To bound:
Next indexUnfortunately, the program was not working... After a quick print test with the variable index, I came to the realization that it was destroyed as soon as the loop exited. So I decided to use the sligtly more efficient :
For index = 0 To boundIt's deffinetly better than repeating the if then and comparisons. But I still feel that the assignment is taking up too much time. In order to make this program truly optimized I want to reuse index. How do I keep the variable index from being destroyed after the loop is exited so I can reuse its value later? Thanks! |
If ou declare a variable inside a loop it only remains for the scope of the
loop, so i would decalre it at the start of the method or make it a gloabal variabel <--- not a good idea to do that one,. |
| All times are GMT -5. The time now is 11:10 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC