Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 7ebd25ac536d248d499a3ce2acda963a > files > 4075

Macaulay2-1.3.1-8.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8" ?>  <!-- for emacs: -*- coding: utf-8 -*- -->
<!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"	 "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>break -- break from a loop</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div><a href="_cache.html">next</a> | <a href="___Boxes.html">previous</a> | <a href="_cache.html">forward</a> | <a href="___Boxes.html">backward</a> | up | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div>

    </td>
  </tr>
</table>
<hr/>
<div><h1>break -- break from a loop</h1>
<div class="single"><h2>Synopsis</h2>
<ul><li><div class="list"><dl class="element"><dt class="heading">Usage: </dt><dd class="value"><div><tt>break x</tt></div>
</dd></dl>
</div>
</li>
<li><div class="single">Consequences:<ul><li>this interrupts execution of a loop controlled by <a href="_for.html" title="for loops">for</a>, <a href="_while.html" title="while loops">while</a>, <a href="_apply.html" title="apply a function to each element">apply</a>, or <a href="_scan.html" title="apply a function to each element">scan</a>, returning <tt>x</tt> as the value of the loop currently being evaluated.</li>
<li>Alternatively, as a top level command in the debugger, it leaves the debugger, returning the user to top level.</li>
</ul>
</div>
</li>
</ul>
</div>
<div class="single"><h2>Description</h2>
<div><p>Omitting <tt>x</tt>, and executing <tt>break</tt>, interrupts execution of a loop as above, returning <a href="_null.html" title="the unique member of the empty class">null</a> as the value of the function currently being evaluated, except, in the case of a <a href="_for.html" title="for loops">for</a> loop or a <a href="_while.html" title="while loops">while</a> loop with a list clause, the list accumulated so far is returned as the value.</p>
<table class="examples"><tr><td><pre>i1 : for i from 1 to 10 do if i == 7 then break hi

o1 = hi

o1 : Symbol</pre>
</td></tr>
</table>
<p>Warning: trying to break from a loop controlled by <a href="_table.html" title="make a table (nested list)">table</a> will probably not do what you expect, since <a href="_table.html" title="make a table (nested list)">table</a> is implemented by two nested loops controlled by <a href="_apply.html" title="apply a function to each element">apply</a>, and only the inner one will stop, as in the following example.</p>
<table class="examples"><tr><td><pre>i2 : table(3,3,(i,j) -> if i == 1 then break 3 else hi)

o2 = {{hi, hi, hi}, 3, {hi, hi, hi}}

o2 : List</pre>
</td></tr>
<tr><td><pre>i3 : table(3,3,(i,j) -> if j == 1 then break 3 else hi)

o3 = {3, 3, 3}

o3 : List</pre>
</td></tr>
</table>
<p>Here is an example as a debugger command.</p>
<table class="examples"><tr><td><pre>i4 : load "Macaulay2Doc/demo1.m2"</pre>
</td></tr>
<tr><td><pre>i5 : g 2
/builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:12:(3):[2]: error: division by zero
/builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:12:(3):[2]: --entering debugger (type help to see debugger commands)
/builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:11-8:13: --source code:
     b := 1/x;</pre>
</td></tr>
<tr><td><pre>ii6 : x

oo6 = 0</pre>
</td></tr>
<tr><td><pre>ii7 : break</pre>
</td></tr>
<tr><td><pre>i8 : g 3

     7
o8 = -
     2

o8 : QQ</pre>
</td></tr>
</table>
</div>
</div>
<div class="single"><h2>See also</h2>
<ul><li><span><a href="_apply.html" title="apply a function to each element">apply</a> -- apply a function to each element</span></li>
<li><span><a href="_scan.html" title="apply a function to each element">scan</a> -- apply a function to each element</span></li>
<li><span><a href="_while.html" title="while loops">while</a> -- while loops</span></li>
<li><span><a href="_for.html" title="for loops">for</a> -- for loops</span></li>
</ul>
</div>
<div class="waystouse"><h2>For the programmer</h2>
<p>The object <a href="_break.html" title="break from a loop">break</a> is <span>a <a href="___Keyword.html">keyword</a></span>.</p>
</div>
</div>
</body>
</html>