Quantcast
Channel: stardot.org.uk
Viewing all articles
Browse latest Browse all 5552

programming • Re: BASIC rules for IF THEN ELSE

$
0
0
I quite regularly get into a terrible muddle with IFs and wonder why my code doesn't work. This is usually when I am trying to combine two IFs on the same line but I want the ELSE to apply to a specific one of them. Quite often I have a "verbose" flag in my code which if true will print more information, usually I use V% for this. So it might be something like

Code:

IF V% THEN IF Z% PRINT "Z% is True":  Do Z% thing ELSE P."Z% is False": Do Not-Z%-thing
But it doesn't work as the ELSE is only encountered when V% is false where Z% might still be true.

Sometimes to get round this I split it up into procedures but it always seems a bit of a "waste" to have to do that...

Code:

IF Z% PROC Zistrue ELSE PROCZisfalse...DEFPROCZistrueIFV% PRINT "Z is true"Do Z thingENDPROC...DEFPROCZisfalseIFV% PRINT "Z is false"Do not-Z thing ENDPROC

Statistics: Posted by BeebMaster — Mon Dec 08, 2025 5:34 pm



Viewing all articles
Browse latest Browse all 5552

Trending Articles