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 / Loop and End

Author
Message
Daarknes
14
Years of Service
User Offline
Joined: 12th Nov 2009
Location: Dothan, Al
Posted: 12th Nov 2009 07:45
I am very new to DBP, and to Basic, and I am having a small problem. For some reason, a 'Loop' or 'End' command at the end of my sample progs always gets rejected at compile time, though all the documentation and tuts say that there are no params for those two commands.



This is just one sample that this has happened on, but I have seen it on most of the tut examples I have tried.

Without Truth there can be no lies, without darkness, no light.
RELLIM
14
Years of Service
User Offline
Joined: 12th Nov 2009
Location:
Posted: 12th Nov 2009 09:12
Quote: "
For some reason, a 'Loop' or 'End' command at the end of my sample progs always gets rejected at compile time
"

It complies just fine on my end. But, there was some logic problems in the code. Try this one and see if it works the way you want to:


Or you could try this one with out the two loops in it:



RELLIM
RELLIM
14
Years of Service
User Offline
Joined: 12th Nov 2009
Location:
Posted: 12th Nov 2009 09:15
I was unaware that my post would not show up right away here is a fix to the second code sample in my post.



RELLIM
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Nov 2009 11:16 Edited at: 12th Nov 2009 11:27
Quote: "I was unaware that my post would not show up right away"


This is explained in the stickies (the threads locked and marked at the top of each board) and when you sign up for the forum you agree that you will read them before posting.

They are worth reading as they contain info that will save you a lot of time in the future.

Daarknes:

Your code snippet compiles and runs without error for me in both DBC and DBP - albeit with different results so your error isn't syntax related.

As far as I am concerned, the tutorial is, let's say... naff. I can see what it's trying to demonstrate, it just doesn't do it because it is written incorrectly (or you have possibly typed it in wrong).

But, it still contains some serious beginner errors.

First of all, please believe me when I say this: "don't have anything to do with any tutorial which uses GOTO - unless it is simply explaining what it does".

Simply ignore the fact that the command exists. It is redundant and should never be needed these days as there are better ways to achieve the same results with procedures and functions. I don't know why tutorials even use Goto because once you get into the habit of using it, it's difficult to get out of it.

Secondly, get into the habit of indenting your code properly. In many cases, this will help you spot hard to find errors in your code - especially later on when your programs get much bigger.

Thirdly, you (and apparently the tutorial you are using) doesn't know the difference between floats and integers.

Tutorial Version Code Working:



I wouldn't have used Goto though...

The Same Snippet Without Goto:



Before you go any further, may I suggest that you check out tutorials 1 to 4 here:

Tutorials For Beginners

After doing those, you may be able to spot similar problems with other tutorials yourself.

TDK

Daarknes
14
Years of Service
User Offline
Joined: 12th Nov 2009
Location: Dothan, Al
Posted: 12th Nov 2009 16:50
Well, first off I spotted several errors in the code snippet straight away, including the fact that it was using INC Health,1 instead of Dec Health,1 and such, but, as far as I know, that should not have caused any problems with the loop function not compiling correctly.


Quote: "This is just one sample that this has happened on, but I have seen it on most of the tut examples I have tried"


Secondly, the original code snippet where I had this problem was written by you, TDK, in your "TDK_Man's Dark Basic Programming for Beginners" that was included in DBProGuide.PDF... might want to look into that..

Without Truth there can be no lies, without darkness, no light.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Nov 2009 19:11
In TDK's defense that tutorial was written in 2006 so it's back when our thoughts about GOTO were more lax. There are things in there that he would never recommend anybody to do today (like using GOTO to exit a DO/LOOP).

Today GOTO is something we avoid but it should be learned and used by newbies until they learn about GOSUB and functions. Once they understand the better method GOTO shouldn't be used anymore since it can cause major problems in huge programs. Click my signature to see why GOTO is bad to use.

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Nov 2009 20:19 Edited at: 12th Nov 2009 20:22
Quote: "Well, first off I spotted several errors in the code snippet straight away, including the fact that it was using INC Health,1 instead of Dec Health,1 and such, but, as far as I know, that should not have caused any problems with the loop function not compiling correctly."


It didn't - it compiled and run (albeit incorrectly) for me and the errors you said you had already spotted simply side-tracked us. That code snippet actually doesn't even need a Do..Loop.

To be honest, you should really have corrected the errors you spotted before posting the code snippet so as not to confuse matters.

Quote: "Secondly, the original code snippet where I had this problem was written by you, TDK, in your "TDK_Man's Dark Basic Programming for Beginners" that was included in DBProGuide.PDF... might want to look into that.."


The snippet you posted was not written by me in any of my tutorials. Which tutorial are you talking about? I've never even heard of the 'DBProGuide.PDF', so I'll have to look into that...

[Edit] Found it! Checking it out now...

If you go through any of my tutorials I have written for DB in the last 10 years I have always said the same thing about Goto - it should be avoided.

I have admittedly used Goto in tutorial code snippets purely to show what it does... and then gone on to say "but don't use it"!

Your real problem seems to be a DBP problem rather than the code snippets you are running. Have you applied any DBP updates yet?

TDK

Daarknes
14
Years of Service
User Offline
Joined: 12th Nov 2009
Location: Dothan, Al
Posted: 12th Nov 2009 22:50
I haven't applied any updates to it yet. I downloaded the free version and have been using it "as is".

I saw in the next segment of the tut where you were saying don't use GOTO anymore, just hadn't got that far when I posted.

Thanks for the quick replies and the positive criticism!

Without Truth there can be no lies, without darkness, no light.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Nov 2009 23:53 Edited at: 13th Nov 2009 00:01
Quote: "I haven't applied any updates to it yet. I downloaded the free version and have been using it "as is"."


Ah I see.

The free version may not be the latest version available as updates can be fairly frequent. Having the full version of DBP I've not downloaded that one, so I'm not 100% sure.

As such, you may not be able to update the free version.

Out of interest, do you still get the same problems if you run any of the snippets posted here?

TDK

Daarknes
14
Years of Service
User Offline
Joined: 12th Nov 2009
Location: Dothan, Al
Posted: 13th Nov 2009 19:35
I just compiled every code snipit posted in this thread, and they all compiled and ran fine, even with the INC error. Which is really odd, because the very first snippet I posted worked as well, and it was a cut and paste from immediately after the compiling errors. I am at a loss as to what was going on, but I can only assume that it was a problem with the DBP software itself.

Without Truth there can be no lies, without darkness, no light.
Daarknes
14
Years of Service
User Offline
Joined: 12th Nov 2009
Location: Dothan, Al
Posted: 13th Nov 2009 19:37
[Edit to Previous] I also just checked for updates and it says it is up-to-date

Without Truth there can be no lies, without darkness, no light.

Login to post a reply

Server time is: 2024-09-28 12:26:13
Your offset time is: 2024-09-28 12:26:13