News:

;) This forum is the property of Proton software developers

Main Menu

Using If with a bit/boolean without an explicit comparison?

Started by Eriond, Mar 28, 2023, 04:14 PM

Previous topic - Next topic

Eriond

I have searched, but came up empty-handed.
Is it possible to use a conditional statement, such as "If" with a bit variable, without explicitly adding a condition after the variable? Thereby assuming that the bit value of 1 equals "true", and hence 0 is equally "false". Ideally I'd like to a syntax such as:
Dim TestBit as Bit = 0
If TestBit Then
 Dostuff
Else
 DontDoStuff
EndIf

John Lawton

Answer is no, your comparison must be of the form:
If TestBit = 1 Then
...
Endif
or
If TestBit = 0 Then
...
Endif
or
Dim bX as Bit
bX = 1
If TestBit = bX Then
...
Endif

Pepe

I agree, if I wouldn't be modifying the basic language syntax.

keytapper

As Cish style, anything that is a non zero value is assumed to be True.
But in positron basic is not used, yet
Ignorance comes with a cost

Stephen Moss

As John indicated you have to use and If x = y Then format it is better because while that is generally the case occasionally when it comes to the occasional PIC register bit and possible other things depending on the circuit design 0 may represent the true state rather than one.

However, if you are asking to make the code more readable for yourself as sometimes 1 or 0 are as clear as you might like, then while you still have the same issue in that 1 may not always represent True you could do...
Symbol True = 1
Symbol False = 0
If x = True then
...
EndIf