Repeat...Until fails with No Such Variable when compiled

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
circe
Posts: 26
Joined: Wed 07 May 2025, 09:26

Repeat...Until fails with No Such Variable when compiled

Post by circe »

I have a somewhat large program with a REPEAT...UNTIL new% => last%. When Compiled with 'Shorten Names' ticked, repeats correctly until condition is met when it fails with No Such Variable.

A workaround is:

Code: Select all

            A%=new% :REM:To avoid problem with compiling Short Names.
            B%=last%
          UNTIL A% => B%
          REM:Equates to  UNTIL new% => last%
So the variables must exist!

Only fails if compiled with Shorten Names ticked and of course does not fail in Immediate mode.
I have not been able to reproduce in a small model so far.
Richard Russell
Posts: 714
Joined: Tue 18 Jun 2024, 09:32

Re: Repeat...Until fails with No Such Variable when compiled

Post by Richard Russell »

circe wrote: Thu 30 Jul 2026, 10:59

Code: Select all

      UNTIL A% => B%
This may be unrelated to your problem, but that is not valid BBC BASIC syntax. It should be A% >= B% not A% => B%. Think greater than or equal to.
I have not been able to reproduce in a small model so far.
I can't investigate further without a Minimal Reproducible Example to run. But if you're looking for a workaround that is less drastic than turning off the Shorten Names option altogether, consider using REM!Keep so that only the variable(s) that are causing the problem are retained in their original 'long' form:

Code: Select all

      REM!Keep new%, last%
          UNTIL new% >= last%
circe
Posts: 26
Joined: Wed 07 May 2025, 09:26

Re: Repeat...Until fails with No Such Variable when compiled

Post by circe »

Thank you Richard. The => vs >= issue was not the problem, but REM!Keep resolves.
I may be wrong, but I do not see a way of reproducing in a small model. If I do find a way, I will post it here.
tpegc
Posts: 6
Joined: Tue 24 Apr 2018, 16:28

Re: Repeat...Until fails with No Such Variable when compiled

Post by tpegc »

Just a thought from my stash of "mistakes I have made" - are you accessing memory directly in any way?
I had reserved memory DIM NUMBER 9 accessed via |NUMBER= which worked until I foolishly also used $NUMBER=MID$(a$,n,n+10) forgetting that $NUMBER would be terminated by CHR$13. Even then it worked by chance in immediate mode and failed in different ways for different compiled variants, one of which was 'No such variable' or something similar.
circe
Posts: 26
Joined: Wed 07 May 2025, 09:26

Re: Repeat...Until fails with No Such Variable when compiled

Post by circe »

Thanks for your reply.
I have had a look through the code and I only use DIM for Arrays and Structures as far as I can see.

Richard's suggestion of using REM!Keep does resolve the issue. I find it curious that ill is OK while the compare fails, and it is only when the compare passes, being unable to find the variables that it has just compared :o .

But many thanks for your input.