BBC BASIC for Windows
General >> Suggestion Box >> missing until or endif not noiced by BASIC.
http://bb4w.conforums.com/index.cgi?board=suggestions&action=display&num=1424161203

missing until or endif not noiced by BASIC.
Post by chrispc on Feb 17th, 2015, 07:20am

It has just dawned on me that if I forget to put in an UNTIL or an ENDIF at the end of section starting with REPEAT or IF, then the program does not give an error message. It would be one more little help for idiots like me if it did. I have just spent a long time looking for an error which turned out to be that I put REM in front of an UNTIL, so disabling it.
Any chance of that error message being added?
chrispc

Re: missing until or endif not noiced by BASIC.
Post by rtr2 on Feb 17th, 2015, 08:53am

on Feb 17th, 2015, 07:20am, chrispc wrote:
Any chance of that error message being added?

Sorry, no. The reason no message is generated is that, as far as the interpreter is concerned, there was no error!

The basic issue here, as I expect you are aware, is that BBC BASIC is a traditional interpreter. The only error checking that it performs is at run time, so it will only report an error if something 'goes wrong' when the program is running.

Take the REPEAT..UNTIL loop. How is the interpreter supposed to 'know' that the UNTIL is missing? It doesn't 'look for' the UNTIL, it simply executes it when it finds it. So the absence of an UNTIL isn't a condition the interpreter is aware of!

The missing ENDIF is a slightly different case. There is a situation in which the interpreter 'looks for' the ENDIF, and that is if the condition is false. In that case it will indeed report a 'Missing ENDIF'. Try running this single-line program:

Code:
      IF FALSE THEN 

But if the condition is true the interpreter has no need to 'look for' the ENDIF (unless an ELSE clause is present) so this program does not report an error, because nothing 'goes wrong':

Code:
      IF TRUE THEN 

The trouble is, of course, that an error like a missing UNTIL or a missing ENDIF may be obvious to you, the programmer, so you think it ought to be obvious to the language too. In the case of a compiled language, or an interpreter that does 'off line' syntax checking, it might be. But to an interpreter that only checks things at run-time it isn't.

The practical solution is to keep an eye on the indentation of your program. If there is a missing ENDIF or a missing UNTIL the indentation at the end of your program will be greater than it was at the beginning! By scanning down the code to see where the indentation goes wrong you should be able to identify the region of the program with the problem.

Richard.
Re: missing until or endif not noiced by BASIC.
Post by KenDown on Nov 15th, 2016, 5:59pm

Coming in late on this topic: there are two situations with indents. One is as Richard indicates if there is a missing ENDIF or UNTIL, but the other is if there is a superfluous ENDIF, UNTIL, NEXT, ENDWHILE etc.

You discover the problem when you notice - if you notice! - that loops etc after the unwanted end statement are no longer indented, or only indented with nested statements.

The only thing to do is start at the beginning of your program and work down until you spot a loop that isn't indented and then look before it for the problem.