Finite state machine: Difference between revisions

Finite state machine en FreeBASIC
(Added 11l)
(Finite state machine en FreeBASIC)
Line 548:
fsm;
end.</lang>
 
 
=={{header|FreeBASIC}}==
{{trans|Phix}}
<lang freebasic>Dim As String state = "READY", KBD = " "
Do
Print KBD
Select Case state
Case "READY"
Print "Machine is READY. (D)eposit or (Q)uit : ";
Do
Do: KBD = Ucase(Inkey): Loop While KBD = ""
If KBD = "D" Then state = "WAITING" : Exit Select
If KBD = "Q" Then state = "QUIT" : Exit Select
Loop
Case "WAITING"
Print "(S)elect product or choose to (R)efund : ";
Do
Do: KBD = Ucase(Inkey): Loop While KBD = ""
If KBD = "S" Then state = "DISPENSE" : Exit Select
If KBD = "R" Then state = "REFUND" : Exit Select
Loop
Case "DISPENSE"
Print "Dispensing product... ";
Print "Please (C)ollect product. : ";
Do
Do: KBD = Ucase(Inkey): Loop While KBD = ""
If KBD = "C" Then state = "READY" : Exit Select
Loop
Case "REFUND"
Print "Please collect refund."
state = "READY"
KBD = " "
Case "QUIT"
Print !"Thank you, shuttingwn now.\n"
Exit Do
End Select
Loop
Sleep</lang>
{{out}}
<pre>
Igual que la entrada de Phix.
</pre>
 
 
=={{header|Go}}==
2,122

edits