Less Than, Greater Than

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

Less Than, Greater Than

Post by MattC » Thu 04 Apr 2019, 15:48


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: 112
Joined: Mon 02 Apr 2018, 18:04

Re: Less Than, Greater Than

Post by DDRM » Fri 05 Apr 2019, 07:54

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: 120
Joined: Mon 02 Apr 2018, 21:51

Re: Less Than, Greater Than

Post by p_m21987 » Mon 08 Apr 2019, 12:27

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

Post Reply