Loops/Continue: Difference between revisions

Content added Content deleted
m (→‎version 1: added highlighting, forced a new line for the OUTPUT header.)
m (→‎{{header|REXX}}: added/changed comments and whitespace.)
Line 1,336: Line 1,336:
===version 1===
===version 1===
(This program could be simpler by using a   '''then/else'''   construct, but an   '''iterate'''   was used to conform to the task.)
(This program could be simpler by using a   '''then/else'''   construct, but an   '''iterate'''   was used to conform to the task.)
<lang rexx>/*REXX program illustrates a DO loop with an ITERATE (continue). */
<lang rexx>/*REXX program illustrates an example of a DO loop with an ITERATE (continue). */


do j=1 for 10 /*equivalent to: DO J=1 TO 10 */
do j=1 for 10 /*this is equivalent to: DO J=1 TO 10 */
call charout , j /*write the integer to terminal. */
call charout , j /*write the integer to the terminal. */
if j//5\==0 then do /*Not a multiple of five? Then..*/
if j//5\==0 then do /*Not a multiple of five? Then ··· */
call charout , ", " /*write a comma to the terminal, */
call charout , ", " /* write a comma to the terminal, ··· */
iterate /*... & then go back for next int*/
iterate /* ··· & then go back for next integer.*/
end
end
say /*force REXX display to next line*/
say /*force REXX to display on next line. */
end /*j*/
end /*j*/
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're all done. */</lang>
Program note: &nbsp; the comma (<big><b>,</b></big>) immediately after the &nbsp; '''charout''' &nbsp; BIF indicates to use the terminal output stream.
Program note: &nbsp; the comma (<big><b>,</b></big>) immediately after the &nbsp; '''charout''' &nbsp; BIF indicates to use the terminal output stream.


Line 1,356: Line 1,356:


===version 2===
===version 2===
<lang rexx>/*REXX program illustrates a DO loop by building a variable for each line.*/
<lang rexx>/*REXX program illustrates an example of a DO loop with an ITERATE (continue). */
$= /*nullify the variable used for display*/
$= /*nullify the variable used for display*/
do j=1 for 10 /*this equivalent to: DO J=1 TO 10 */
do j=1 for 10 /*this is equivalent to: DO J=1 TO 10 */
$=$ || j', ' /*append the integer to a placeholder. */
$=$ || j', ' /*append the integer to a placeholder. */
if j//5==0 then say left($, length($)-2) /*J a multiple of five? Say.*/
if j//5==0 then say left($, length($) - 2) /*Is J a multiple of five? Then SAY.*/
if j==5 then $= /*start the display line over again. */
if j==5 then $= /*start the display line over again. */
end /*j*/
end /*j*/
/*stick a fork in it, we're all done. */</lang>
/*stick a fork in it, we're all done. */</lang>
'''output''' &nbsp; is the same as the 1<sup>st</sup> REXX version. <br><br>
'''output''' &nbsp; is the same as the 1<sup>st</sup> REXX version. <br><br>