Loops/While: Difference between revisions

→‎{{header|REXX}}: corrected the messed up deletion and modification of two REXX versions, added program comments and re-installed the various REXX section comments. -- ~~~~
(→‎{{header|REXX}}: corrected the messed up deletion and modification of two REXX versions, added program comments and re-installed the various REXX section comments. -- ~~~~)
Line 1,082:
 
=={{header|REXX}}==
<lang rexx>/*REXX program to showdemonstrates a DO WHILE construct. */
===Version 1, right justified===
j=1024 /*define the initial value of j.*/
do while j>0 /*test if made at the top of do.*/
say end</lang>j
j=j%2 /*in REXX, % is integer division.*/
end
/*stick a fork in it, we're done.*/</lang>
{{'''output}}'''
<pre style="height:30ex;overflow:scroll">
x=1024
512
256
128
64
32
16
8
4
2
1
</pre>
 
===Versionversion 12, right justified===
Note that a faster version could be implemented with
<br>::::: '''DO WHILE x\==0'''
<br>but that isn't compliant with the wording of the task.
<lang rexx>/*REXX program to showdemonstrates a DO WHILE construct. */
x=1024 /*define the initial value of x.*/
x=1024
do while x>0 /*test if made at the top of do.*/
say right(x,10) /*pretty up the output by aligning. right*/
x=x%2 /*in REXX, % is integer division. */
end</lang>
/*stick a fork in it, we're done.*/</lang>
{{output}}
'''output'''
<pre style="height:30ex;overflow:scroll">
1024
512
256
128
64
32
16
8
4
2
1
</pre>
 
===Version 23, faster WHILE comparison===
<lang rexx>/*REXX program to show a DO WHILE construct. */
<lang rexx>/*REXX program demonstrates a DO WHILE construct. */
x=1024
x=1024 do while x>>0 /*this is an exact comparison. /*define the initial value of x.*/
do while say right(x,10)>>0 /*prettythis upis thean output byexact aligning comparison. */
say right(x=x%2,10) /*in REXX, % pretty isoutput integerby division.aligning right*/
x=x%2 /*in REXX, % is integer division.*/
end</lang>
end
'''output''' is the same as version 1.
/*stick a fork in it, we're done.*/</lang>
'''output''' is the same as version 12.
<br><br>
 
=={{header|Ruby}}==