Finite state machine: Difference between revisions

(Finite state machine en FreeBASIC)
Line 552:
=={{header|FreeBASIC}}==
{{trans|Phix}}
<lang freebasic>DimEnum As String state = "READY", KBD = " "states
READY
WAITING
DISPENSE
REFUND
QUIT
End Enum '-- (or just use strings if you prefer)
 
Dim As states state = READY
Dim As String 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 SelectDo
If KBD = "Q" Then state = "QUIT" : Exit SelectDo
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 SelectDo
If KBD = "R" Then state = "REFUND" : Exit SelectDo
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 SelectDo
Loop
Case "REFUND"
Print "Please collect refund."
state = "READY"
KBD = " "
Case "QUIT"
Print !"Thank you, shuttingwn now.\n"
Exit Do
Line 595 ⟶ 604:
Igual que la entrada de Phix.
</pre>
 
 
=={{header|Go}}==
2,136

edits