![]() |
|
Nesting _IFF - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Nesting _IFF (/showthread.php?tid=4466) |
Nesting _IFF - Dimster - 02-12-2026 Doesn't appear to be addressed in the wiki or KotD, but how do you nest _IIF or is that's not possible, but if it is, how deep can it be nested? RE: Nesting _IFF - a740g - 02-12-2026 You can. For example: Code: (Select All)
But I have never checked how deep though. I'd suggest not overdoing it. IMO, more than 2 levels makes a code hard to read. RE: Nesting _IFF - SMcNeill - 02-12-2026 (02-12-2026, 10:29 PM)a740g Wrote: You can. For example: If your code is getting to this point and depth of IIFing, then I'd IIFing just use SELECT CASE. It's much more readable to me. Code: (Select All)
One glance at the above and I can decipher what the heck it's doing with no thought or brain power really needed. That compound IFF statement? It's not intuitive. I'd have to stop and take a moment to wrap my brain around it, and that makes it much less viable as *GOOD* code, in my opinion. Just because you CAN do something doesn't mean you really should. It's often better to just stick to the simple constructs which you (and everyone else) recognize and understand inherently. It makes sharing, upkeeping, and maintaining code a helluva lot easier over time. RE: Nesting _IFF - Dimster - 02-13-2026 Thanks for the info. I'm finding I really like a lot of the new logic operators and I read somewhere that _IIF could replace If..Then..Else but it appears _IIF can not handle multiple blocks like Elseif (unless we come up with an _ElseIIF). Truthfully I gave up on IF..THEN.. ELSEIF in favour of Select Case. And as I understand it, _IIF is restricted to True/False, it can't for example call a subroutine if the condition is met - ie result = (_IIF(age<13,Child,Adult). We would then need a further IF statement ( ie If result = Child then Underage). to call a subroutine to deal with Children. And I hear the groans ... "Gave them a new toy and they broke it already". I got to go back to that article and re-read it. Again, thanks for the discussion. RE: Nesting _IFF - Jack - 02-13-2026 I agree with Steve, the only advantage of IIF is that you can use it in an expression but even then it's harder to mentally process than a simple if then else RE: Nesting _IFF - OldMoses - 02-13-2026 I've used compound _IIF statements, and I agree the readability is somewhat poor. That said, I was using a lot of branchless equations and minimizing variables as a coding style and they were far worse to read. It seems to me that if you are looking for short circuiting decisions in complex expressions, then _IIF is somewhat better than my old methods. At least for readability. Here's a nightmare expression vl% = (MinOf%(vl% + ch%, 5) * (bs% > 0)) * (md% = 0) + ((-MinOf%(vl% + ch%, 5)_ * (vl% > 5) - MinOf%(vl% + ch%, vl%) * (vl% <= 5)) * (bs% = 0) - MinOf%(vl% + ch%, 5) * (bs% > 0)) * (md% > 0) It did exactly what it was supposed to do, but try to wrap your brain around it. The MinOf% function was my homebrewed _MAX command. I suspect that _IIF would be a piece of cake compared to it.
RE: Nesting _IFF - Kernelpanic - 02-13-2026 Something's still missing! ![]() Code: (Select All)
RE: Nesting _IFF - NakedApe - 02-13-2026 Haha. Case Is > 95: Print "Very, very senior" You must mean that, right?
|