Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > b38d2da330d1936e5ab1307c039c4941 > files > 506

octave-doc-3.6.4-3.mga4.noarch.rpm

<html lang="en">
<head>
<title>The do-until Statement - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Statements.html#Statements" title="Statements">
<link rel="prev" href="The-while-Statement.html#The-while-Statement" title="The while Statement">
<link rel="next" href="The-for-Statement.html#The-for-Statement" title="The for Statement">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="The-do-until-Statement"></a>
<a name="The-do_002duntil-Statement"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="The-for-Statement.html#The-for-Statement">The for Statement</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="The-while-Statement.html#The-while-Statement">The while Statement</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Statements.html#Statements">Statements</a>
<hr>
</div>

<h3 class="section">10.4 The do-until Statement</h3>

<p><a name="index-g_t_0040code_007bdo_002duntil_007d-statement-702"></a>
The <code>do-until</code> statement is similar to the <code>while</code> statement,
except that it repeatedly executes a statement until a condition becomes
true, and the test of the condition is at the end of the loop, so the
body of the loop is always executed at least once.  As with the
condition in an <code>if</code> statement, the condition in a <code>do-until</code>
statement is considered true if its value is non-zero, and false if its
value is zero.  If the value of the conditional expression in a
<code>do-until</code> statement is a vector or a matrix, it is considered
true only if it is non-empty and <em>all</em> of the elements are non-zero.

   <p>Octave's <code>do-until</code> statement looks like this:

<pre class="example">     do
       <var>body</var>
     until (<var>condition</var>)
</pre>
   <p class="noindent">Here <var>body</var> is a statement or list of statements that we call the
<dfn>body</dfn> of the loop, and <var>condition</var> is an expression that
controls how long the loop keeps running.

   <p>This example creates a variable <code>fib</code> that contains the first ten
elements of the Fibonacci sequence.

<pre class="example">     fib = ones (1, 10);
     i = 2;
     do
       i++;
       fib (i) = fib (i-1) + fib (i-2);
     until (i == 10)
</pre>
   <p>A newline is not required between the <code>do</code> keyword and the
body; but using one makes the program clearer unless the body is very
simple.

   </body></html>