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

General FreeBASIC programming questions.
D.J.Peters
Posts: 7667
Joined: May 28, 2005 3:28

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

Postby D.J.Peters » Dec 29, 2018 17:30

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: 415
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Short form of the NOT operator with Boolean ?

Postby Josep Roca » Dec 29, 2018 17:42

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: 1299
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Short form of the NOT operator with Boolean ?

Postby badidea » Dec 29, 2018 17:42

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: 2755
Joined: Jun 02, 2015 16:24

Re: Short form of the NOT operator with Boolean ?

Postby Tourist Trap » Dec 29, 2018 17:43

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: 889
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Short form of the NOT operator with Boolean ?

Postby SARG » Dec 29, 2018 17:44

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

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

Re: Short form of the NOT operator with Boolean ?

Postby D.J.Peters » Dec 29, 2018 17:53

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

Joshy

Return to “General”

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 4 guests