This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
Idiom #45 Pause execution for 5 seconds
Sleep for 5 seconds in current thread, before proceeding with the next instructions.

- Ada
- C
- C
- Clojure
- Clojure
- C++
- C#
- C#
- D
- Dart
- Dart
- Elixir
- Erlang
- Fortran
- Go
- Haskell
- JS
- JS
- JS
- Java
- Java
- Kotlin
- Lisp
- Lua
- Lua
- Obj-C
- PHP
- Pascal
- Perl
- Python
- Ruby
- Rust
- Scala
- Scheme
- Smalltalk
- VB
(<! (timeout 5000))
Blocks in an asynchronous fashion.
using namespace std::chrono_literals;
std::this_thread::sleep_for(5s);
Process.sleep(5000)
Sleeps the current process.
Argument is either the number of milliseconds to sleep as an integer or the atom :infinity. When :infinity is given, the current process will suspend forever.
Argument is either the number of milliseconds to sleep as an integer or the atom :infinity. When :infinity is given, the current process will suspend forever.
module M_time
contains
subroutine system_sleep(wait)
use,intrinsic :: iso_c_binding, only: c_int
integer,intent(in) :: wait
integer(kind=c_int):: waited
interface
function c_usleep(msecs) bind (C,name="usleep")
import
integer(c_int) :: c_usleep
integer(c_int),intent(in),VALUE :: msecs
end function c_usleep
end interface
if(wait.gt.0)then
waited=c_usleep(int(wait,kind=c_int))
endif
end subroutine system_sleep
end module M_time
program x
use M_time
call system_sleep(5000000)
end
Fortran does not have an intrinsic to pause for a specified time period, but it is relatively easy to create an interface to a POSIX C routine
setTimeout(function(){
// Instructions after delay
},5000);
Javascript does not have a sleep function. This execution flow is structured with a callback (it can be a closure).
Unit is millisecond.
Unit is millisecond.
local start = os.clock()
while os.clock() - start < 5 do end
Warning: this is busy-looping, which is very inefficient.
os.execute(package.config:sub(1,1) == "/" and "sleep 5" or "timeout 5")
Checks the path delimiter to tell the OS, then executes the appropriate sleep command.