if and text: bug or feature?

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
This
iff cond then
text
...
endtext
endiff

works as expected.
But this
if cond text
...
endtext

works fine if the condition is true. If it is false, then things go haywire and as far as I can tell subsequent batch lines are swallowed (not executed) until a return (this was in a subroutine).
 

rconn

Administrator
Staff member
May 14, 2008
10,101
85
#2
> This
> iff cond then
> text
> ...
> endtext
> endiff
> works as expected.
> But this
> if cond text
> ...
> endtext
> works fine if the condition is true. If it is false, then things go
> haywire and as far as I can tell subsequent batch lines are swallowed (not
> executed) until a return (this was in a subroutine).
WAD - and you *really* wouldn't want it to work any other way.

If an IF condition fails, IF will not execute the command, so the parser has
no way to know that you're trying to use a TEXT / ENDTEXT. The only way it
could know that would be to expand and execute the command in every
instance, which would render the IF moot! :-)

Bottom line - never, never, put a TEXT / ENDTEXT in an IF statement.

Rex Conn
JP Software
 
#3
You may want to add a warning to the documentation of IF. I figured out what was going on but it took a while. Once I understood, I also had a good idea of what your response would be ;) too.

It just bugs me if there are exceptions to general rules (in my old age strike that... mature years I have trouble remembering them) and especially undocumented ones.