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.

2.5 Evaluation of Expressions 345In this case, overflow is not generated,<strong>and</strong> the Catch has no effect.In[19]:= Catch[ 2 + g[5] ]Out[19]= 122Functions like Continue[ ] <strong>and</strong> Break[ ] allow you to “transfer control” to the beginning or endof a loop in a Mathematica program. Sometimes you may instead need to transfer control to a particularelement in a Mathematica procedure. If you give a Label as an element in a procedure, you can useGoto to transfer control to this element.This goes on looping until q exceeds 6.In[20]:= (q = 2 Label[begin] Print[q] q += 325If[q < 6, Goto[begin]])Note that you can use Goto in a particular Mathematica procedure only when the Label it specifiesoccurs as an element of the same Mathematica procedure. In general, use of Goto reduces the degree ofstructure that can readily be perceived in a program, <strong>and</strong> therefore makes the operation of the programmore difficult to underst<strong>and</strong>.Web 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!