37 lines
790 B
Plaintext
37 lines
790 B
Plaintext
/* To exit the innermost block, use return(<value>) */
|
|
|
|
block([n],
|
|
do (
|
|
n: random(20),
|
|
ldisp(n),
|
|
if n = 10 then return(),
|
|
n: random(20),
|
|
ldisp(n)
|
|
)
|
|
)$
|
|
|
|
/* To exit any level of block, use catch(...) and throw(<value>);
|
|
they are not used for catching exceptions, but for non-local
|
|
return. Use errcatch(...) for exceptions. */
|
|
|
|
block([n],
|
|
catch(
|
|
do (
|
|
n: random(20),
|
|
ldisp(n),
|
|
if n = 10 then throw('done),
|
|
n: random(20),
|
|
ldisp(n)
|
|
)
|
|
)
|
|
)$
|
|
|
|
/* There is also break(<value>, ...) in Maxima. It makes Maxima
|
|
stop the evaluation and enter a read-eval loop where one can change
|
|
variable values, then return to the function after exit; For example */
|
|
|
|
block([x: 1], break(), ldisp(x));
|
|
> x: 2;
|
|
> exit;
|
|
2
|