-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcountdown_timer.jl
47 lines (37 loc) · 1.19 KB
/
countdown_timer.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Countdown timer in Julia
function run_timer()
print("Enter the amount of seconds: ")
seconds = parse(Int64, readline())
println("Countdown starts now with $seconds seconds remaining.")
current_seconds = seconds
# While the countdown timer is not finished
while current_seconds != 0
# Print the current countdown
if current_seconds != seconds
println("Seconds left: $current_seconds")
end
# Wait for one second
sleep(1)
current_seconds = current_seconds - 1
end
println("The countdown is over!")
end
# Call the run_timer function in a loop until the user quits it
function countdown_timer()
# While the user chooses to run the countdown timer
while true
print("Do you want set a countdown timer? (1=Yes/0=No): ")
answer = parse(Int64, readline())
# Convert the string value input to a number
if answer == 1
# Run the timer
run_timer()
elseif answer == 0
println("Exiting...")
break # Stop the countdown timer
else
println("Invalid input, please try again")
end
end
end
countdown_timer()