Not, is a operator, but not is a function
Not, is a operator, but not is a function
How can I simplify this code?
If a
a = 0
Else
a = 1
EndIf
In other languages is very easy (a = NOT a), but in PB not works.
Thanks in advance
If a
a = 0
Else
a = 1
EndIf
In other languages is very easy (a = NOT a), but in PB not works.
Thanks in advance
-
- Addict
- Posts: 2345
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Not, is a operator, but not is a function
Works here:SP wrote:How can I simplify this code?
If a
a = 0
Else
a = 1
EndIf
In other languages is very easy (a = NOT a), but in PB not works.
Thanks in advance
Code: Select all
a.l = 0
Debug (Not a) Or #False
a.l = 1
Debug (Not a) Or #False
bye,
Daniel
Daniel
I guess you have to use parantheses like this:
Code: Select all
a = (Not a)
The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents. (Nathaniel Borenstein)
http://www.wirednerd.com
http://www.wirednerd.com
-
- Addict
- Posts: 2345
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
And this one works, too:
But first one is more secure afaik, because purebasic doesn't know boolean expressions, it's more like a integer expression.
Code: Select all
a.l = 0
Debug (Not a)
a.l = 1
Debug (Not a)
bye,
Daniel
Daniel
This works here, but it is definetely not intentional:
Code: Select all
a.l = 0
a = _ Not a
Debug a
a.l = 1
a = _ Not a
Debug a
Re: Not, is a operator, but not is a function
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: Not, is a operator, but not is a function
Too much:
Code: Select all
; Original code
a = 5
If a
a = 0
Else
a = 1
EndIf
Debug a
; Your code
a = 5
a=1-a
Debug a
Re: Not, is a operator, but not is a function
@Trond: The original code by SP does not specify that a=5, and only shows
that he wants to toggle between 0 and 1, which is exactly what a=1-a does.
@SP: In PureBasic you'd do it like this:
Because PureBasic uses ~ instead of Not in your original post. Observe:
that he wants to toggle between 0 and 1, which is exactly what a=1-a does.
@SP: In PureBasic you'd do it like this:
Code: Select all
a=~a
Code: Select all
Repeat
a=~a
Debug a
c+1
Until c=4
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: Not, is a operator, but not is a function
No, since the original post does not specify what a is you cannot assume that it is either 0 or 1. It could be -4562.PB wrote:@Trond: The original code by SP does not specify that a=5, and only shows
that he wants to toggle between 0 and 1, which is exactly what a=1-a does.
The code does not toggle between 0 and 1, it toggles between 0 and not 0. It says "if a", not "if a = 1".
I might as well post this:
Code: Select all
a=1
Re: Not, is a operator, but not is a function
To toggle between 0 and 1 a!1 is easier but in his code it seems that "true" is not "1" but "non zero"
Dri
Dri
Re: Not, is a operator, but not is a function
> the original post does not specify what a is you cannot assume
True, but I was taking an educated guess based on the fact that no specific
info was provided that enabled us to be 100% sure of his intentions, especially
when you consider he gave an example of "a = Not a", so it's obvious that he
wanted a toggle of some sort, and his code referenced both 0 and 1, so I think
it was a very good assumption to make.
True, but I was taking an educated guess based on the fact that no specific
info was provided that enabled us to be 100% sure of his intentions, especially
when you consider he gave an example of "a = Not a", so it's obvious that he
wanted a toggle of some sort, and his code referenced both 0 and 1, so I think
it was a very good assumption to make.

I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- Enthusiast
- Posts: 423
- Joined: Fri Apr 25, 2003 5:22 pm
- Contact:
just 2 cents:
you might toggle a between any two values x and y by using:
So e.g. between 42 and 24
you might toggle a between any two values x and y by using:
Code: Select all
x = 1234
y = -17
toggle = y ! x
a = x
a ! toggle
a ! toggle
...
Code: Select all
a = 24
toggle = 50 ; 42 ! 24
a ! toggle
a ! toggle
...
%1>>1+1*1/1-1!1|1&1<<$1=1