ibm-information-center/dist/eclipse/plugins/i5OS.ic.rbam6_5.4.0.1/doforcmd.htm

89 lines
5.2 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="DOFOR command" />
<meta name="abstract" content="The DOFOR command lets you process a group of commands a specified number of times." />
<meta name="description" content="The DOFOR command lets you process a group of commands a specified number of times." />
<meta name="DC.subject" content="DOFOR (Do For) command, Do For (DOFOR) command, command, CL, DOFOR (Do For), Do For (DOFOR), example, DOFOR command" />
<meta name="keywords" content="DOFOR (Do For) command, Do For (DOFOR) command, command, CL, DOFOR (Do For), Do For (DOFOR), example, DOFOR command" />
<meta name="DC.Relation" scheme="URI" content="contp.htm" />
<meta name="DC.Relation" scheme="URI" content="../clfinder/finder.htm" />
<meta name="DC.Relation" scheme="URI" content="../cl/dofor.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="doforcmd" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>DOFOR command</title>
</head>
<body id="doforcmd"><a name="doforcmd"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">DOFOR command</h1>
<div><p>The DOFOR command lets you process a group of commands a specified
number of times.</p>
<div class="section"><p>The <span class="cmdname">Do For (DOFOR)</span> command specifies a variable,
its initial value, an increment or decrement amount, and a terminal value
condition. The format of the <span class="cmdname">Do For (DOFOR)</span> command is:</p>
<pre>DOFOR VAR(integer-variable) FROM(initial-value) TO(end-value) BY(integer-constant)</pre>
<p>When processing of a DOFOR group is begun, the integer-variable
specified on the VAR parameter is initialized to the initial-value specified
on the FROM parameter. The value of the integer-variable is compared to the
end-value as specified on the TO parameter. When the integer-constant on
the BY parameter is positive, the comparison checks for integer-variable greater
than the end-value. If the integer-constant on the BY parameter is negative,
the comparison checks for integer-variable less than the end-value.</p>
<p>If
the condition is not true, the body of the DOFOR group is processed. When
the ENDDO is reached, the integer-constant from the BY parameter is added
to the integer-value and the condition is evaluated again.</p>
<p>The following
is an example of conditional processing with a <span class="cmdname">Do For (DOFOR)</span> command.</p>
<pre>CHGVAR &amp;INT2 0
DOFOR VAR(&amp;INT) FROM(2) TO(4) BY(1)
.
.
.
CHGVAR &amp;INT2 (&amp;INT2 + &amp;INT)
ENDDO
/* &amp;INT2 = 9 after running the DOFOR group 3 times */
</pre>
<p>When the DOFOR group is processed, &amp;INT is initialized
to 2 and the value of &amp;INT is checked to see if it is greater than 4.
It is not, so the body of the group is processed. On the second iteration
of the group, one is added to &amp;INT and the check is repeated. It is less
than 4, so the DOFOR group is processed again. On reaching the ENDDO the
second time, the value of &amp;INT is again incremented by 1. &amp;INT now
has a value of 4. Since &amp;INT is still less than or equal to 4, the DOFOR
group is processed again. On reaching the ENDDO the third time, the value
of &amp;INT is again incremented by 1. This time, the value is 5, and processing
continues with the command following the ENDDO.</p>
<p>The LEAVE command may
be used to exit the DOFOR group and resume processing following the ENDDO.
The ITERATE command may be used to skip the remaining commands in the group,
increment the controlling variable, and evaluate the end-value condition immediately.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="contp.htm" title="You can use commands to change the flow of logic within your CL procedure.">Control processing within a CL procedure</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../clfinder/finder.htm">CL command finder</a></div>
<div><a href="../cl/dofor.htm">Do For (DOFOR) command</a></div>
</div>
</div>
</body>
</html>