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 / Does code go right through line labels?

Author
Message
Da_Rhyno
13
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 23rd Sep 2011 04:49
Say I had some code like this...



Does that subroutine _my_line_label continue on through _skip_to_end to Return, or does it infer there's a return before _skip_to_end?
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 23rd Sep 2011 05:13
The flow of the program will first call My_line_label via gosub, where it render the text statement then hits RETURN. Upon return, execution continues on from the next line after the Gosub My_line_label. So it'll happily execute code at and beyond My_Line_Label section of code until it hits the RETURN statement, where it should error at this point.

Labels are treated as markers, they don't actually prohibit the program flow of execution from the entering a labeled section without being called. If that's what you want to it's time to look at Functions.


To stop the second execution of the sub routine in you example you'd need to END, or jump past to some other Location.





In real world app using sub routines, you'd structure the project so you're not jumping around all over the place though. Personally if you're going to use GOTO/GOSUB then set yourself a rule and stick to it. Like Goto/Gosub may only branch forward and not inside nests.


ie.




It's also helpful to set up sub-routines so that have a single entry point and single exit point.

Da_Rhyno
13
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 23rd Sep 2011 05:19
Thanks!

I've actually programmed for a good 8-9 years now, and I actually want to be able to skip certain code in my subroutines, which is why I asked. It saves me having to use multiple variables for everything. Which can become a real mess in the longrun...

Login to post a reply

Server time is: 2024-11-22 12:15:49
Your offset time is: 2024-11-22 12:15:49