Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Question about for next

Author
Message
zeddex2
17
Years of Service
User Offline
Joined: 4th Mar 2007
Location:
Posted: 21st Mar 2007 15:18
Is it possible in a for next loop,. to put 2 variable like this

for i = 1 to 10 and j = 20 to 40
??? if yes how can i write it becose DBP don t want it.
If no, i don t have any choice to make 2 for next loop ?

If you can, I can!
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 21st Mar 2007 15:31
I'm a DB Classic user, so I'm not sure if this will be of any help, but it might be worth a go.

Assuming you mean: i=1 so do j=20, j=21, j=22...j=39, j=40 and then i=2 so do j=20, j=21, j=22...j=39, j=40 etc., this might work:



Hope this helps.

On our way 'ome, on our way 'ome...
zeddex2
17
Years of Service
User Offline
Joined: 4th Mar 2007
Location:
Posted: 21st Mar 2007 15:34
is not good,

becose i want to make 1 for next loop to check at the same time, the i = 1 to 10 and anothere variable j = 30 to 40

is like if you make object cube 1 to 10 and make object sphere 30 to 40 and in 1 for next you want check both, cube and sphere.

If you can, I can!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 21st Mar 2007 17:29 Edited at: 21st Mar 2007 17:29
If I understand you correctly, and I'm not sure I do...



TDK_Man

zeddex2
17
Years of Service
User Offline
Joined: 4th Mar 2007
Location:
Posted: 21st Mar 2007 18:27
why i didnt think about that,



Tk TDK i give you a for that

If you can, I can!
Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 21st Mar 2007 21:14
Well then you may aswell do-

And save the computer from having to do if tests each time.

zeddex2
17
Years of Service
User Offline
Joined: 4th Mar 2007
Location:
Posted: 21st Mar 2007 22:26
deamon if i make 2 for next loop, that mean the programe as to roll over and over 2 time instead of just 1

If you can, I can!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 22nd Mar 2007 00:01
zeddex2:

Your method would actually be slower as there are three extra 'If i' conditions each run through the loop and there are 50 loop iterations - of which 30 of them are not required.

If you use the counting variable i directly as in my snippet, your loop only runs through 10 times and there's no need for any If..Thens at all.

Speed might not be an issue now, but if your program gets bigger it may become an issue so it's better to optimize early rather than later...

TDK_Man

Login to post a reply

Server time is: 2024-11-25 22:46:13
Your offset time is: 2024-11-25 22:46:13