Sleep: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
No edit summary |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 898:
=={{header|COBOL}}==
COBOL 2023 introduced the <code>AFTER</code> phrase of the <code>CONTINUE</code> statement to specify a time period in seconds for which execution will be suspended, which, depending on implementation, could be not an integer.
There are two methods for putting the program to sleep, both requiring unofficial extensions.▼
{{works with|COBOL 2023}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Sleep-In-Seconds.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Seconds-To-Sleep USAGE IS FLOAT-LONG.
PROCEDURE DIVISION.
ACCEPT Seconds-To-Sleep
DISPLAY "Sleeping..."
CONTINUE AFTER Seconds-To-Sleep SECONDS
GOBACK.▼
▲
The first expects the amount of time to be in seconds.
{{works with|ACUCOBOL-GT}}
{{works with|
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Sleep-In-Seconds.
Line 907 ⟶ 926:
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Seconds-To-Sleep USAGE IS COMP-2.
*> Note: COMP-2, while supported on most implementations, is
*> non-standard. FLOAT-SHORT is the proper USAGE for Native
*> IEEE 754 Binary64 Floating-point data items.
PROCEDURE DIVISION.
ACCEPT Seconds-To-Sleep
DISPLAY "Sleeping..."
CALL "C$SLEEP" USING BY CONTENT Seconds-To-Sleep
DISPLAY "Awake!"
GOBACK.
▲ GOBACK
▲ .</syntaxhighlight>
While the second expects the time to be in nanoseconds. Note: Windows systems can only sleep to the nearest millisecond.
{{works with|
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Sleep-In-Nanoseconds.
OPTIONS.
DEFAULT ROUNDED MODE IS NEAREST-AWAY-FROM-ZERO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Seconds-To-Sleep USAGE
01 Nanoseconds-To-Sleep USAGE
01 Nanoseconds-Per-Second CONSTANT AS 1000000000.
PROCEDURE DIVISION.
ACCEPT Seconds-To-Sleep
END-COMPUTE
DISPLAY "Sleeping..."
CALL "CBL_OC_NANOSLEEP"
USING BY CONTENT Nanoseconds-To-Sleep
END-CALL
DISPLAY "Awake!"
GOBACK.
END PROGRAM Sleep-In-Nanoseconds.</syntaxhighlight>
▲ GOBACK
▲ .</syntaxhighlight>
=={{header|Common Lisp}}==
Line 1,081 ⟶ 1,103:
})
}</syntaxhighlight>
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
print "How many seconds should I sleep? "
sec = number input
print "Sleeping ..."
sleep sec
print "Awake!"
</syntaxhighlight>
=={{header|EGL}}==
Line 1,469 ⟶ 1,500:
}
}</syntaxhighlight>
===Using Java 8===
<syntaxhighlight lang="java">
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public final class Sleep {
public static void main(String[] args) {
try {
System.out.println("Enter time to sleep in milliseconds:");
Scanner scanner = new Scanner(System.in);
final int delay = scanner.nextInt();
scanner.close();
System.out.println("Sleeping...");
TimeUnit.MILLISECONDS.sleep(delay);
System.out.println("Awake!");
} catch (InputMismatchException | InterruptedException exception) {
exception.printStackTrace(System.err);;
}
}
}
</syntaxhighlight>
{{ out }}
<pre>
Enter time to sleep in milliseconds:
4321
Sleeping...
Awake!
</pre>
=={{header|JavaScript}}==
Line 2,599 ⟶ 2,664:
=={{header|Wren}}==
<syntaxhighlight lang="
import "io" for Stdin, Stdout
|