Less Than, Greater Than

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Posts: 57
Joined: Mon 16 Apr 2018, 06:17

Less Than, Greater Than

Post by MattC »


I was just playing around with a loop which required a value of a variable to be between two values. The normal way seems to be a double expression, i.e.

UNTIL A% > 10 AND A% < 20

Is there any way a combined expression could be used? I.e.

[ UNTIL 10 < A% < 20 ]

I tried playing around with various formats/parentheses, but was unable to come up with any combination that worked. Is this one of those examples that just wont work in BASIC?


Posts: 216
Joined: Mon 02 Apr 2018, 18:04

Re: Less Than, Greater Than

Post by DDRM »

Hi Matt,

In that case, I guess you could use

UNTIL ABS(15-A%)>4

...but I'm not sure it would be significantly faster, and I'm fairly sure it's significantly less clear (and you have to be more careful about boundary conditions), so I'm not sure I'd recommend it.

Best wishes,


Posts: 149
Joined: Mon 02 Apr 2018, 21:51

Re: Less Than, Greater Than

Post by p_m21987 »

DDRM is right. It's best to just write A% > 10 AND A% < 20.