13.07.2015 Views

2.5.9 Loops and Control Structures - Wolfram Research

2.5.9 Loops and Control Structures - Wolfram Research

2.5.9 Loops and Control Structures - Wolfram Research

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

344 2. Principles of MathematicaWhen k 5, Return[big]] t = x^3 Return[t - 7])In[16]:= f[10]Out[16]= bigReturn[expr] allows you to exit a particular function, returning a value. Mathematica also providesa capability for non-local returns with which you can exit a sequence of nested functions. Non-localreturns can be convenient for h<strong>and</strong>ling certain error conditions.This function “throws” overflow if itsargument is greater than 10.g[20] throws overflow, whichisreturned as the value of the enclosingCatch.In[17]:= g[x_] := If[x > 10, Throw[overflow], x!]In[18]:= Catch[ 2 + g[20] ]Out[18]= overflowWeb sample page from The Mathematica Book, Second Edition, by Stephen <strong>Wolfram</strong>, published by Addison-Wesley Publishing Company (hardcoverISBN 0-201-51502-4; softcover ISBN 0-201-51507-5). To order Mathematica or this book contact <strong>Wolfram</strong> <strong>Research</strong>: info@wolfram.com;http://www.wolfram.com/; 1-800-441-6284.© 1991 <strong>Wolfram</strong> <strong>Research</strong>, Inc. Permission is hereby granted for web users to make one paper copy of this page for their personal use. Further reproduction,or any copying of machine-readable files (including this one) to any server computer, is strictly prohibited.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!