[metapost] exitif usage
luigi scarso
luigi.scarso at gmail.com
Wed Feb 15 23:25:24 CET 2017
On Wed, Feb 15, 2017 at 7:36 PM, Walt Burkhard <burkhard at cs.ucsd.edu> wrote:
> Hello,
>
> I am using exitif within my metapost program and find many surprising output
> statements. It seems that when the exitif statement is nested within a
> for statement as well as two if statements, these output messages appear.
>
> Here is a very short program to demonstrate this behavior.
>
> beginfig (1) ;
> for a = 0 upto 10 :
> %% if ( a > 3 ) :
> if ( a < 6 ) :
> x := a*a ;
> exitif ( x > 20 )
> fi ;
> message ( decimal x ) ;
> %% fi ;
> endfor ;
> endfig ;
>
> beginfig (2) ;
> for a = 0 upto 10 :
> if ( a > 3 ) :
> if ( a < 6 ) :
> x := a*a ;
> exitif ( x > 20 )
> fi ;
> message ( decimal x ) ;
> fi ;
> endfor ;
> endfig ;
> end
>
> Here is the output along with the warning message ---
>
> 0
> 1
> 4
> 9
> 16 [1]
> 16 [2] )
> (end occurred when if on line 22 was incomplete)
> 2 output files written: test.1 .. test.2
>
> Is there a mechanism to turn off such warning messages?
hm no, I fear not, it's a check hardcoded in the final cleanup.
Why not this:
beginfig (2) ;
x:=0;
for a = 0 upto 10 :
if ( a > 3 ) :
if ( a < 6 ) :
x := a*a ;
fi ;
message "1) x=" & ( decimal x ) ;
fi ;
if (x>20): message "Quit!" ; fi %useless, just to write something
exitif ( x > 20 );
endfor ;
message "2) x=" & ( decimal x ) ;
endfig ;
end
Hans Hanges cooked this one
def quit_fi_fi_fi =
fi fi fi
exitif true
enddef ;
for a = 0 upto 10 :
message "a=" & (decimal a);
if ( a > 3 ) :
if ( a < 6 ) :
x := a*a ;
message "0) x= " & (decimal x) ;
if x > 20 :
message "Quit!" ;
quit_fi_fi_fi ;
fi ;
fi ;
message "1) x= " & (decimal x) ;
fi ;
endfor ;
message "2) x=" & (decimal x) ;
end
--
luigi
More information about the metapost
mailing list