Handle a signal: Difference between revisions

Content added Content deleted
(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: Line 1,105:


=={{header|REXX}}==
=={{header|REXX}}==
REXX has no SLEEP function that is built into the language.
REXX has no   '''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.*/


Some operating systems that REXX runs under have a &nbsp; '''SLEEP''' &nbsp; or equivalent BIF.
call time 'E' /*reset the REXX elapsed timer. */
signal on halt /*HALT is signaled via a Ctrl─C.*/


<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 shows 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*/
do forever; u=time('E') /*get the elapsed time in seconds./
call time 'Reset' /*reset the REXX elapsed timer. */
if u<t |, /* ◄═══ means we passed midnight.*/
signal on halt /*HALT: signaled via a Ctrl─C in DOS.*/
u>t+.5 then iterate j /* ◄═══ means we passed ½ second.*/
end /*forever*/
end /*j*/


do j=1 /*start with 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. */
t=time('E') /*get the REXX elapsed time in seconds.*/
do forever; u=time('Elapsed') /* " " " " " " " */
if u<t | u>t+.5 then iterate j /* ◄═══ passed midnight or ½ second. */
end /*forever*/
end /*j*/


halt: say 'program HALTed, it ran for' format(time("ELapsed"),,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>
<pre>
1
1
Line 1,156: Line 1,153:
</pre>
</pre>
Note: some REXX interpreters don't show the
Note: some REXX interpreters don't show the
<b>
<pre>
<pre>
^C
^C
</pre>
</pre>
</b>
when &nbsp; <big> Ctrl-C </big> &nbsp; is pressed.
<br><br>


=={{header|Ruby}}==
=={{header|Ruby}}==