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 / Command line switcher

Author
Message
grclaeys
13
Years of Service
User Offline
Joined: 14th Apr 2011
Location:
Posted: 15th Apr 2011 05:02
Hello, I am new to DarkBasic Professional. I recently encountered a problem. I did not know how to make my program jump back to a previous command line. What is the code to do this (if possible) and how do you do this. Thank you.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 15th Apr 2011 10:44
To continuously repeat a section of code, you will have to put it in a loop. Here is an example:



You also have the option of specifying when to exit the loop by either using a repeat...until loop, or a while...endwhile loop.





You also have the option to break out of the do..loop with the exit command.



I hope this helps you, please post if you have any other problems.

TheComet

grclaeys
13
Years of Service
User Offline
Joined: 14th Apr 2011
Location:
Posted: 18th Apr 2011 02:35
Thanks, but I was wondering how to do this without using a loop
Agent
20
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 18th Apr 2011 11:44 Edited at: 18th Apr 2011 11:47
Hey Grclaeys,

Although you may not immediately realise it, or why, doing what you're asking how to do is one of the big no-no's in programming. Jumping back to a previous point in code execution without using a loop is done using a command called GOTO, and you'll never find an experienced programmer using this command because it causes a billion different problems, not the least of which is unreadable code. You will find any number of arguments against its use, and probably none at all for it, if you use the search term GOTO on these forums.

I strongly, strongly suggest you do not get used to using GOTO, ever, but since you asked, this is the answer.



A word of caution: If you have GOTO statements in your code, nobody will be willing to help you fix it if you develop problems. This is not because we are unfriendly, stubborn stodges, but because it is impossible to understand code that uses GOTO, even for experienced programmers. This is the main rease GOTO is a no-no.

With that said, next comes the word of advice: There is no situation, none whatsoever, that requires the use of GOTO. All programming problems can be solved with alternatives. If you do not see a way to solve your project without using GOTO, then you'll find the process of learning an alternative most informative.

I cannot overstate how important it is to avoid using GOTO. It is the single, most forbidden command in the programming universe. I only discuss it here because you asked a very specific question, but for your own sake, please look into the alternatives.

grclaeys
13
Years of Service
User Offline
Joined: 14th Apr 2011
Location:
Posted: 18th Apr 2011 16:50
Thanks for the help.
Wyldhunt
15
Years of Service
User Offline
Joined: 27th Sep 2009
Location: The Dark Side
Posted: 23rd Apr 2011 05:07
I'll second Agents vote to not use GOTO. That's what I was mentioning, in your first thread asking this question, about making spaghetti code. (btw: Usually best to keep it all in one thread so that we can have all the related info in one place.)

What is it that you're trying to do, exactly?
Chances are, it would be better to make a function or loop or any of the other methods of code flow control.

If you can post a code example that shows us why you would need this, we could probably help you out a lot more than to tell you how not to do it.

Login to post a reply

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