Suspicious logic operation, mixed boolean and non-boolean

New to FreeBASIC? Post your questions here.
N3trunn3r
Posts: 97
Joined: Feb 14, 2008 15:48

Suspicious logic operation, mixed boolean and non-boolean

Postby N3trunn3r » Jul 27, 2020 16:41

Code: Select all

if any_integer = 4 or any_integer = 5 or key_left = true or key_right = true then

Will not compile: Suspicious logic operation, mixed boolean and non-boolean

What is the best solution here? A one-liner would be good.
fxm
Posts: 9908
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Suspicious logic operation, mixed boolean and non-boolean

Postby fxm » Jul 27, 2020 16:50

That compiles but with warnings.

Otherwise, for example:
if Cbool(any_integer = 4 or any_integer = 5) or key_left = true or key_right = true then
MrSwiss
Posts: 3599
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Suspicious logic operation, mixed boolean and non-boolean

Postby MrSwiss » Jul 27, 2020 17:48

N3trunn3r wrote:What is the best solution here?

More efficient (using boolean short-cut operators: AndAlso/OrElse):
If CBool(any_integer = 4 OrElse any_integer = 5) OrElse (key_left OrElse key_right) Then

key_... must represent a Boolean variable! Those are automatically checked for TRUE.
any_integer could as well be called: any_num_var, because it could also be Single/Double.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 3 guests