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 / What is a Syntax error and What is a Nesting error?

Author
Message
Raybrite2
16
Years of Service
User Offline
Joined: 16th May 2009
Location: Cyberspace
Posted: 14th Jun 2009 14:42
I actually have two questions.
What is a Syntax error and What is a nesting error.
I get them at the end of my program and don't know what to do about them.
I am also confused about how to count the line numbers in Dark Basic. They said line 52 and I could only count about 42 with spaces.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Jun 2009 15:13
Syntax is the order you write commands and values.
Syntax is important in human languages too; if I wrote that sentence as "important is in human languages too syntax" you'd have a hard time understanding me.
Every command has a proper syntax, the correct way to use it, you can find these in the help file.

Nesting errors occur when you use an opening statement (ie For, Do, Repeat, While) and forget to use the corresponding closing statement (ie Next, Loop, Until, Endwhile). You can make this mistake a lot if you don't indent your code.

Have a read of this http://forum.thegamecreators.com/?m=forum_view&t=138230&b=10

I would also recommend going through TDK's tutorial (found at the top of this board) as they start off with the basics and take you through to more advanced stuff.

There is an eight letter word. You can insert a letter into it or remove a letter from it without changing its meaning. Answer
Raybrite2
16
Years of Service
User Offline
Joined: 16th May 2009
Location: Cyberspace
Posted: 14th Jun 2009 15:48
TDK's Tutorials are reprinted with the code snippets and pictures in the DB Pro manual at the top of that forum. I printed out TDK's and today I printed out the DB Pro book. That is where I am getting the problem. It is with the latter part of the random number program in part one.
Also, I have been indenting and just noticed that they cover it in section 2.
they also cover the loops in section 2.
I am going to keep trying to figure this out.
I highlight the code in the DB lite program and then hit F1. It doesn't recognize any commands. I am not certain it is working in my program.
Also, I added the try again part into the temperature program they have and it worked fine.(??)
Raybrite2
16
Years of Service
User Offline
Joined: 16th May 2009
Location: Cyberspace
Posted: 14th Jun 2009 16:02
This is the code that is giving me the problem.
( I cannot figure out how to use the Code Snippet thing.)

Randomize Timer():
Start:
MyNumber=Rnd(99)+1

Do:
CLS:
Print "I have thought of a number between 1 and 100. See how quickly you can guess it!"
Print
Input "What is your guess?", Guess
Print
If Guess < MyNumber:
Print "Your guess was too low. Try again."
Sleep 2000
Endif
If Guess >MyNumber:
Print "Your guess was too high. Try again."
Sleep 2000
Endif
If Guess = MyNumber:
Print "Your guess was correct. Well Done!!"
Print
Print "Do you want to play again? (Y/N)"
Repeat:
I$=Upper$(Inkey$()): rem Read the keyboardfor keypresses.
Until I$="Y" or I$="N"
If I$="Y":
Goto Start:
Else
CLS:
Print:"Goodbye..."
End:
Endif
Endif
Loop

My problem is showing up with the second line after the Read Keyboard line.(Until I$="Y" or I$="N")
I didn't put in all the rem statements this time.
arbiter chewbacca hybrid
16
Years of Service
User Offline
Joined: 30th Nov 2008
Location:
Posted: 14th Jun 2009 16:40
See that code box in the top corner of the post editor hight your code and press the button




Vista is a paradox created by Bill Gates to force the noble pc gamers of america to console I am here to change that. [link]www.kdlproductions.webs.com[link]
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 14th Jun 2009 19:26 Edited at: 14th Jun 2009 19:29
first off try indenting your code like this:



see how you indent every time you enter either a loop (do....loop) or call an if

this way every do lines up with its loop and every if lines up with its else and endif

this makes it MUCH easier to check for nesting errors

as you will see you have an extra endif just before the loop, thats whats causing the error

also you're using colons all wrong, they arent used after commands (except in the case of goto or gosub labels like your Start, they are used for organization to put multiple commands on the same line, like this:



vs



and about the code snippet box, just copy and paste the code into the post, hihglight it and press the "code" button above the emoticions

There are only 10 kinds of people in the world, those who understand binary and those who dont
Raybrite2
16
Years of Service
User Offline
Joined: 16th May 2009
Location: Cyberspace
Posted: 15th Jun 2009 01:49
I indented the code. I also took out the colons.
That made things look a lot better and straightened out a lot.
I also took out the endif statement. It is in the book even though I thought it was extra.
I am having a problem now with a nesting loop with the loop statement. I cannot figure that one out.
It also comes straight out of the book.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 15th Jun 2009 02:04
paste what you have now and ill be glad to help

There are only 10 kinds of people in the world, those who understand binary and those who dont
Grog Grueslayer
Valued Member
20
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 15th Jun 2009 03:58
Quote: "I also took out the endif statement. It is in the book even though I thought it was extra.
I am having a problem now with a nesting loop with the loop statement. I cannot figure that one out."


Usually you have a nesting error when you take out what you think are extra ENDIF statements. And That1Smart Guy is right... post code so we can see the problem.

That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 15th Jun 2009 03:59
its done man, see the other thread, I 4get wat its called

There are only 10 kinds of people in the world, those who understand binary and those who dont

Login to post a reply

Server time is: 2025-06-08 09:06:09
Your offset time is: 2025-06-08 09:06:09