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 / On the subject of the so-called dreaded goto

Author
Message
gearce
17
Years of Service
User Offline
Joined: 18th Dec 2006
Location: ex SCOTLAND, now MELBOURNE, Australia
Posted: 23rd Jan 2007 03:48
Newcomers Corner or Code Snippets?

I decided to post here because all my previous postings have been here.

As I wrote in one of my postings,

Quote: "
My DBClassic programming skills are on a continual learner level so I'd like to hear from you if you can offer a different (not necessarily better) way of writing any part of any of the programmes.
"


In light of that, and looking at the following snippets (all from the same programme)in which there are 32 goto's in total, could the code have been written differently, thereby avoiding the so-called dreaded goto?

None in this snippet but this part of the code, together with the subroutine checkselection:, in the next snippet, forms a loop until a selection has been made.



In this snippet, there's 28 goto's. 27 go to a label re_turn: within the subroutine and 1 to a label noselection: as in the snippet above



Here we have 2 goto's, each of which go to a label here: within the function



and finally there's 2 here, one going to the start of the programme and one to the end of the programme. There's also two exit statements in this one. What's the view on these?

This is part of a subroutine as can be seen from the return statement



Would be interested to hear

gearce

LANG MAY YER LUM REEK
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 23rd Jan 2007 23:29
Code Snippets is for code you can use in your projects. I'll move it to Newcomers Corner



IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Jan 2007 23:58
For the second piece of code, I'd suggest putting the numbers into data statements and using them to populate arrays that can be used in a for loop. Then I'd put a loop around that that would repeat until a selection was made.

Piece 3 just needs a simple flag that would determine whether the current character would be displayed or not.

The last piece is a little more difficult, not because of the code you show, but because of the code you don't. Your main loop can be a while/endwhile or repeat/until based upon a flag. If the flag is set, your loop exits.

It's a little hard to suggest stuff based on mini-snippits, but I hope that gives you the right idea.

Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 24th Jan 2007 06:44
believe me its dreaded theres some posts floating around that explains why, do a forum search on GOTO

gearce
17
Years of Service
User Offline
Joined: 18th Dec 2006
Location: ex SCOTLAND, now MELBOURNE, Australia
Posted: 24th Jan 2007 10:22
Thanks folks.

To BatVink. Sorry about that

To IanM. Much appreciated. Will work on your advice

To Kieran. Point taken

gearce

LANG MAY YER LUM REEK

Login to post a reply

Server time is: 2024-09-25 17:26:09
Your offset time is: 2024-09-25 17:26:09