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.

DarkBASIC Discussion / Simply question about exiting a DO LOOP and sub-routines

Author
Message
oDCo
20
Years of Service
User Offline
Joined: 11th May 2005
Location:
Posted: 12th May 2005 05:00
Hello all,

Forgive me if this is a really stupid question but can someone please tell me why this simple program is repeating the sub-routine before exiting the program?

It even runs the sub-routine if you set var to 1 at the start of the code.

Thanks in advance,

David
oDCo
20
Years of Service
User Offline
Joined: 11th May 2005
Location:
Posted: 12th May 2005 05:07
Ekk, why did the code go? I'll try again

BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th May 2005 05:20
Quote: "Error obtaining Source Code, invalid ID. Sorry but I've given up."


Post your code in your message, the source button is a little unreliable.

BatVink
oDCo
20
Years of Service
User Offline
Joined: 11th May 2005
Location:
Posted: 12th May 2005 05:30
Opps, I'll try again

oDCo
20
Years of Service
User Offline
Joined: 11th May 2005
Location:
Posted: 12th May 2005 05:45
Thanks Mods
hyrichter
21
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 12th May 2005 12:23
The reason it's repeating your subroutine is because that's all that's left for it to do after it exits the loop. DB is a little different than languages like VB, where a sub is never run until it is called. DB looks at code line by line, so when it exits the loop, it just goes onto the next line which is your sub. Then at the end of your sub, it doesn't have anywhere to return to, so it ends.

What you need to do is change your exit to "end." Or if you want a fancy ending sequence, send it to a separate subroutine.

Hopefully that makes a little sense.

oDCo
20
Years of Service
User Offline
Joined: 11th May 2005
Location:
Posted: 12th May 2005 17:43
That make perfect sense, thanks hyrichter

Login to post a reply

Server time is: 2025-05-23 00:22:37
Your offset time is: 2025-05-23 00:22:37