Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 3e60ff9d4d6f58c8fbd17208f14089fa > files > 229

octave-doc-3.2.3-3mdv2010.0.i586.rpm

<html lang="en">
<head>
<title>Increment Ops - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Expressions.html#Expressions" title="Expressions">
<link rel="prev" href="Assignment-Ops.html#Assignment-Ops" title="Assignment Ops">
<link rel="next" href="Operator-Precedence.html#Operator-Precedence" title="Operator Precedence">
<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="Increment-Ops"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Operator-Precedence.html#Operator-Precedence">Operator Precedence</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Assignment-Ops.html#Assignment-Ops">Assignment Ops</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Expressions.html#Expressions">Expressions</a>
<hr>
</div>

<h3 class="section">8.7 Increment Operators</h3>

<p><em>Increment operators</em> increase or decrease the value of a variable
by 1.  The operator to increment a variable is written as &lsquo;<samp><span class="samp">++</span></samp>&rsquo;.  It
may be used to increment a variable either before or after taking its
value.

   <p>For example, to pre-increment the variable <var>x</var>, you would write
<code>++</code><var>x</var>.  This would add one to <var>x</var> and then return the new
value of <var>x</var> as the result of the expression.  It is exactly the
same as the expression <var>x</var><code> = </code><var>x</var><code> + 1</code>.

   <p>To post-increment a variable <var>x</var>, you would write <var>x</var><code>++</code>. 
This adds one to the variable <var>x</var>, but returns the value that
<var>x</var> had prior to incrementing it.  For example, if <var>x</var> is equal
to 2, the result of the expression <var>x</var><code>++</code> is 2, and the new
value of <var>x</var> is 3.

   <p>For matrix and vector arguments, the increment and decrement operators
work on each element of the operand.

   <p>Here is a list of all the increment and decrement expressions.

     <dl>
<dt><code>++</code><var>x</var><dd><a name="index-g_t_002b_002b-541"></a>This expression increments the variable <var>x</var>.  The value of the
expression is the <em>new</em> value of <var>x</var>.  It is equivalent to the
expression <var>x</var><code> = </code><var>x</var><code> + 1</code>.

     <br><dt><code>--</code><var>x</var><dd><a name="index-g_t_0040code_007b_002d_002d_007d-542"></a>This expression decrements the variable <var>x</var>.  The value of the
expression is the <em>new</em> value of <var>x</var>.  It is equivalent to the
expression <var>x</var><code> = </code><var>x</var><code> - 1</code>.

     <br><dt><var>x</var><code>++</code><dd><a name="index-g_t_002b_002b-543"></a>This expression causes the variable <var>x</var> to be incremented.  The
value of the expression is the <em>old</em> value of <var>x</var>.

     <br><dt><var>x</var><code>--</code><dd><a name="index-g_t_0040code_007b_002d_002d_007d-544"></a>This expression causes the variable <var>x</var> to be decremented.  The
value of the expression is the <em>old</em> value of <var>x</var>. 
</dl>

   </body></html>