Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Does QB64pe already have a function like IFF ?
#6
I get by like this:

Code: (Select All)
dim i as _integer64, f as _float, x as _integer64, y as _float, s as string
i = iff(x > 5, x - 1, x * 2)
f = ifff(y < 0, 1, sqr(y))
s = iffs$(x = 0, "true", "false")
end

function iff&& (cond%%, truevalu&&, falsvalu&&)
    if cond%% then
        iff&& = truevalu&&
        exit function
    end if
    iff&& = falsvalu&&
end function

function ifff## (cond%%, truevalu##, falsvalu##)
    if cond%% then
        ifff## = truevalu##
        exit function
    end if
    ifff## = falsvalu##
end function

function iffs$ (cond%%, truevalu as string, falsvalu as string)
    if cond%% then
        iffs$ = truevalu
        exit function
    end if
    iffs$ = falsvalu
end function

It requires three functions, one for integers, another for floating point and another for strings, that's the main drawback. But be glad BASIC doesn't have a "boolean" type that would have prevented the straight-out use of a condition which is evaluated and passed along as integer value.
Reply


Messages In This Thread
RE: Does QB64pe already have a function like IFF ? - by mnrvovrfc - 06-03-2023, 10:32 PM



Users browsing this thread: 1 Guest(s)