Suspicious logic operation, mixed boolean and non-boolean

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

Suspicious logic operation, mixed boolean and non-boolean

Post by N3trunn3r »

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
Moderator
Posts: 12591
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

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

Post by fxm »

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: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

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

Post by MrSwiss »

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.
Post Reply