How does Purebasic handle 'true false' as well as &
-
- New User
- Posts: 3
- Joined: Mon Jul 28, 2008 1:33 pm
- Location: Brussels
How does Purebasic handle 'true false' as well as &
Look at the simple program below and to Debug's Output .
Question : how should one code
If (i=0)&(j=0)
for this program to work ?
Thanks,
Eric Morlet
i.w
j.w
tf.w
i=0
j=1
tf=(i=j)
Debug tf
Debug (i <= j)
Debug (i >= j)
If (i=0)&(j=0)
Debug i
Debug j
Debug "i=0 And j=0"
EndIf
;=======================================
; Debug Output:
1
1
1
0
1
i=0 And j=0
Question : how should one code
If (i=0)&(j=0)
for this program to work ?
Thanks,
Eric Morlet
i.w
j.w
tf.w
i=0
j=1
tf=(i=j)
Debug tf
Debug (i <= j)
Debug (i >= j)
If (i=0)&(j=0)
Debug i
Debug j
Debug "i=0 And j=0"
EndIf
;=======================================
; Debug Output:
1
1
1
0
1
i=0 And j=0
- Fluid Byte
- Addict
- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Please use code tags and indention, it's hard to read.
But what is your problem anyway? You can't just ask how modify some random line in the code if we don't now what you are trying to do.
The following is just a wild guess:
But what is your problem anyway? You can't just ask how modify some random line in the code if we don't now what you are trying to do.
The following is just a wild guess:
Code: Select all
i.w
j.w
tf.w
i=0
j=1
tf=(i=j)
Debug tf
Debug (i <= j)
Debug (i >= j)
If (i=0) And (j=0)
Debug i
Debug j
Debug "i=0 And j=0"
EndIf
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
From the manual :
& : Bitwise AND. You should be familiar with binary numbers when using this operator. The result of this operator will be the value of the expression on the LHS anded with the value of the expression on the RHS, bit for bit. The value of each bit is set according to the table below. Additionally, if the result of the operator is not used and there is a variable on the LHS, then the result will be stored directly in that variable. This operator cannot be used with strings.
And : Logical AND. Can be used to combine the logical true and false results of the comparison operators to give a result shown in the following table.
LHS | RHS | Result
-----------------------
false | false | false
false | true | false
true | false | false
true | true | true
& : Bitwise AND. You should be familiar with binary numbers when using this operator. The result of this operator will be the value of the expression on the LHS anded with the value of the expression on the RHS, bit for bit. The value of each bit is set according to the table below. Additionally, if the result of the operator is not used and there is a variable on the LHS, then the result will be stored directly in that variable. This operator cannot be used with strings.
Code: Select all
; Shown using binary numbers as it will be easier to see the result
a.w = %1000 & %0101 ; Result will be 0
b.w = %1100 & %1010 ; Result will be %1000
bits = a & b ; AND each bit of a and b and use result in equals operator
a & b ; AND each bit of a and b and store result directly in variable "a"
LHS | RHS | Result
-----------------------
false | false | false
false | true | false
true | false | false
true | true | true
Code: Select all
If i = 0 And j = 0
Debug "Both i and j are equal to zero"
EndIf
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
"&" is a bitwise operator, "And" is the logical operator.
(i=0), (j=0) resp. (i <= j) are boolean expressions and not supported in PureBasic.
if you want to check both variables for false, you can write
If i=0 And j=0
or even
If Not i And Not j
[edith]
little demonstration of the difference of "&" and "And":
(i=0), (j=0) resp. (i <= j) are boolean expressions and not supported in PureBasic.
if you want to check both variables for false, you can write
If i=0 And j=0
or even
If Not i And Not j
[edith]
little demonstration of the difference of "&" and "And":
Code: Select all
a = %1111001111001111
b = %1010101010101010
If a And b
Debug "both variables are not false"
EndIf
Debug "now the bitwise and:"
Debug Bin(a & b)
oh... and have a nice day.
Hio man!
Welcome !
Sorry, but, actually you can't use this syntax :
I had the same little problem here
If we want to write a complex operation only in one line, we must replace it by a little procedure, for example :
And use it, like that:
Caution /!\ Cause you must create one procedure per type of variable !
(For example, EqualF() for float, et caetera...)
Caution too, cause not having this allows you to use the two logic supports in the same program :It's a advantage !
Bye!
Welcome !

Sorry, but, actually you can't use this syntax :
Code: Select all
Debug (b = c)
If we want to write a complex operation only in one line, we must replace it by a little procedure, for example :
Code: Select all
Procedure Equal(LHS.L, RHS.L)
Protected Result.L
If LHS = RHS: Result = -1: Else: Result = 0: EndIf
ProcedureReturn Result
EndProcedure
Code: Select all
Debug Equal(a, b)
(For example, EqualF() for float, et caetera...)
Caution too, cause not having this allows you to use the two logic supports in the same program :
Code: Select all
Logic A : True = 1
Logic B : True = -1
Bye!
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
there is a dirty workaround to provide boolean expressions:
connect the expression logically with a boolean value:
CAUTION:
this is just a dirty workaround, there is no guarantee it would work in future PB-Versions.
connect the expression logically with a boolean value:
Code: Select all
a = 7
b = 5
Debug ( (a > b) Or #False )
Debug ( (a > b) And #True )
this is just a dirty workaround, there is no guarantee it would work in future PB-Versions.
oh... and have a nice day.
http://www.xs4all.nl/~bluez/datatalk/pu ... evaluation
http://www.xs4all.nl/~bluez/datatalk/pu ... lculations
http://www.xs4all.nl/~bluez/datatalk/pu ... lculations
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )