Finite state machine: Difference between revisions
Content added Content deleted
(add →{{header|Perl 6}}) |
|||
Line 1,011: | Line 1,011: | ||
$machine.run("ready");</lang> |
$machine.run("ready");</lang> |
||
=={{header|Phix}}== |
|||
<lang Phix>enum READY, WAITING, DISPENSE, REFUND, QUIT -- (or just use strings if you prefer) |
|||
integer state = READY, ch = ' ' |
|||
while true do |
|||
printf(1,"%c\n",ch) |
|||
switch state do |
|||
case READY: printf(1,"Machine is READY. (D)eposit or (Q)uit :") |
|||
while true do |
|||
ch = upper(wait_key()) |
|||
if ch='D' then state = WAITING exit end if |
|||
if ch='Q' then state = QUIT exit end if |
|||
end while |
|||
case WAITING: printf(1,"(S)elect product or choose to (R)efund :") |
|||
while true do |
|||
ch = upper(wait_key()) |
|||
if ch='S' then state = DISPENSE exit end if |
|||
if ch='R' then state = REFUND exit end if |
|||
end while |
|||
case DISPENSE: printf(1,"Dispensing product...") |
|||
printf(1,"Please (C)ollect product. :") |
|||
while true do |
|||
ch = upper(wait_key()) |
|||
if ch='C' then state = READY exit end if |
|||
end while |
|||
case REFUND: printf(1,"Please collect refund.") |
|||
state = READY |
|||
ch = ' ' |
|||
case QUIT: printf(1,"Thank you, shutting down now.\n") |
|||
exit |
|||
end switch |
|||
end while</lang> |
|||
{{out}} |
|||
<pre> |
|||
Machine is READY. (D)eposit or (Q)uit :D |
|||
(S)elect product or choose to (R)efund :S |
|||
Dispensing product...Please (C)ollect product. :C |
|||
Machine is READY. (D)eposit or (Q)uit :D |
|||
(S)elect product or choose to (R)efund :R |
|||
Please collect refund. |
|||
Machine is READY. (D)eposit or (Q)uit :Q |
|||
Thank you, shutting down now. |
|||
</pre> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |