Spaces in expressions
Posted: Sun May 07, 2017 9:51 pm
Page 80 of the Basic Language Reference says in part:
"Spaces are don’t care :
A = 5 + 3 is the same as a=5+3"
I realise this is to do with comparisons in this instance, but I just spent a while trying to debug a very simple programme and the issue turned out to be due to spaces.
using a as a variable:
Initially variable a had a value of 1234, I wanted to increment this value within a loop so I used a=a+1; the value did not increment.
There were other factors involving sending the value of a in a udp packet and I thought initially the problem was somehow involved in that, after all a=a+1 is simple, right?
I then added spaces in the expressions
a=a+1 became a = a + 1 and it worked. I played around a little and found that as long as there was a space between a and = all was fine e.g.
a =a+1 would work
my curiosity was piqued now so, remembering back to early days of basic (40+years ago!!) I remember one strain of basic would not allow single character variables so I tried aa as the variable. In this case, any combinations of spaces worked e.g.
aa=aa+1
aa=aa + 1
aa = aa + 1 etc
Not sure whether this is a bug or not?
"Spaces are don’t care :
A = 5 + 3 is the same as a=5+3"
I realise this is to do with comparisons in this instance, but I just spent a while trying to debug a very simple programme and the issue turned out to be due to spaces.
using a as a variable:
Initially variable a had a value of 1234, I wanted to increment this value within a loop so I used a=a+1; the value did not increment.
There were other factors involving sending the value of a in a udp packet and I thought initially the problem was somehow involved in that, after all a=a+1 is simple, right?
I then added spaces in the expressions
a=a+1 became a = a + 1 and it worked. I played around a little and found that as long as there was a space between a and = all was fine e.g.
a =a+1 would work
my curiosity was piqued now so, remembering back to early days of basic (40+years ago!!) I remember one strain of basic would not allow single character variables so I tried aa as the variable. In this case, any combinations of spaces worked e.g.
aa=aa+1
aa=aa + 1
aa = aa + 1 etc
Not sure whether this is a bug or not?