Handle a signal: Difference between revisions

m
→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations, add comments in the REXX section header and output section.
(Added COBOL)
m (→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations, add comments in the REXX section header and output section.)
Line 1,105:
 
=={{header|REXX}}==
REXX has no SLEEP  '''sleep'''   function that is built into the language.
<br>Some operating systems that REXX runs under have a '''SLEEP''' or equivalent function.
<br><br>But, there's more than one way to skin a cat. (No offense to cat lovers.)
<lang rexx>/*REXX program displays integers until a Ctrl─C is pressed, then show*/
/* the number of seconds that have elapsed since start of pgm execution.*/
 
<br>Some operating systems that REXX runs under have a &nbsp; '''SLEEP''' &nbsp; or equivalent functionBIF.
call time 'E' /*reset the REXX elapsed timer. */
signal on halt /*HALT is signaled via a Ctrl─C.*/
 
<br><br>But, there's more than one way to skin a cat. &nbsp; (No offense to cat lovers.)
do j=1 /*start with 1 and go ye forth. */
<lang rexx>/*REXX program displays integers until a Ctrl─C is pressed, then showshows the number of */
say right(j,20) /*display integer right-justified*/
/*────────────────────────────────── seconds that have elapsed since start of execution.*/
t=time('E') /*get the elapsed time in seconds*/
call time 'Reset' do forever; u=time('E') /*getreset the REXX elapsed timetimer. in seconds. */
signal on halt if u<t |, /*HALT: signaled via a ◄═══ meansCtrl─C we passedin midnightDOS.*/
u>t+.5 then iterate j /* ◄═══ means we passed ½ second.*/
end /*forever*/
end /*j*/
 
do j=1 /*start with 1 unity and go ye forth. */
say 'Program control should never ever get here, said Captain Dunsel.'
say right(j,20) /*display the integer right-justified. */
call time t=time('E') /*resetget the REXX elapsed timer.time in seconds.*/
do forever; u=time('Elapsed') /* " " " " " " " */
if u<t | u>t+.5 then iterate j /* ◄═══ meanspassed wemidnight or passed ½ second. */
end /*forever*/
end /*j*/
 
halt: say 'program HALTed, it ran for' format(time("EELapsed"),,2) 'seconds.'
/*──────────────────────────────────HALT subroutine─────────────────────*/
/*stick a fork in it, we're all done. */</lang>
halt: say 'program HALTed, it ran for' format(time("E"),,2) 'seconds.'
'''output'''
/*stick a fork in it, we're done.*/</lang>
{{out}}
<pre>
1
Line 1,156 ⟶ 1,153:
</pre>
Note: some REXX interpreters don't show the
<b>
<pre>
^C
</pre>
</b>
when &nbsp; <big> Ctrl-C </big> &nbsp; is pressed.
<br><br>
 
=={{header|Ruby}}==