[solved]Short form of the NOT operator with Boolean ?

General FreeBASIC programming questions.
Post Reply
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

[solved]Short form of the NOT operator with Boolean ?

Post by D.J.Peters »

Why you can't toggle a Boolean with the short form of the NOT operator ?

Joshy

Code: Select all

dim as boolean bool
bool not= bool ' <-- toggle
print bool : sleep
Last edited by D.J.Peters on Dec 29, 2018 17:53, edited 1 time in total.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Short form of the NOT operator with Boolean ?

Post by Josep Roca »

Not= is not implemened, but = Not is just as short.

Code: Select all

dim as boolean bool
bool = not bool ' <-- toggle
print bool
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Short form of the NOT operator with Boolean ?

Post by badidea »

D.J.Peters wrote:Why you can't toggle a Boolean with the short form of the NOT operator ?

Joshy

Code: Select all

dim as boolean bool
bool not= bool ' <-- toggle
print bool : sleep
That would be bool = bool not bool which is weird
bool = not bool does the job

Edit: too late

Edit2: Alternative: bool xor= true
Last edited by badidea on Dec 29, 2018 18:16, edited 1 time in total.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Short form of the NOT operator with Boolean ?

Post by Tourist Trap »

D.J.Peters wrote:Why you can't toggle a Boolean with the short form of the NOT operator ?

Joshy

Code: Select all

dim as boolean bool
bool not= bool ' <-- toggle
print bool : sleep
Hello Joshy,

here (1.06.0 win32 64bits) it doesn't compile, "Expected '=', found 'not'".
But I confess I don't see how it could work. NOT is a unary operator, so it's not like × and so on.
In a *= 2, we have equivalently a = 2*a. But a Not= b would mean a = a Not b. It doesn't make too much sense for me.
Even if I see the advantage of a toggle like a = Not a. Some typo you made?

Edit : very too late , hard competition here :)
SARG
Posts: 1756
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Short form of the NOT operator with Boolean ?

Post by SARG »

With other dataypes the same.
Simply use bool = not bool ......

I also lost the race :-)
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Short form of the NOT operator with Boolean ?

Post by D.J.Peters »

I see I ignored the fact that is an "unary" operator.

Joshy
Post Reply