Finite state machine: Difference between revisions

Content added Content deleted
(Finite state machine en FreeBASIC)
Line 552: Line 552:
=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
{{trans|Phix}}
{{trans|Phix}}
<lang freebasic>Dim As String state = "READY", KBD = " "
<lang freebasic>Enum 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
Do
Print KBD
Print KBD
Select Case state
Select Case state
Case "READY"
Case READY
Print "Machine is READY. (D)eposit or (Q)uit : ";
Print "Machine is READY. (D)eposit or (Q)uit : ";
Do
Do
Do: KBD = Ucase(Inkey): Loop While KBD = ""
Do: KBD = Ucase(Inkey): Loop While KBD = ""
If KBD = "D" Then state = "WAITING" : Exit Select
If KBD = "D" Then state = WAITING : Exit Do
If KBD = "Q" Then state = "QUIT" : Exit Select
If KBD = "Q" Then state = QUIT : Exit Do
Loop
Loop
Case "WAITING"
Case WAITING
Print "(S)elect product or choose to (R)efund : ";
Print "(S)elect product or choose to (R)efund : ";
Do
Do
Do: KBD = Ucase(Inkey): Loop While KBD = ""
Do: KBD = Ucase(Inkey): Loop While KBD = ""
If KBD = "S" Then state = "DISPENSE" : Exit Select
If KBD = "S" Then state = DISPENSE : Exit Do
If KBD = "R" Then state = "REFUND" : Exit Select
If KBD = "R" Then state = REFUND : Exit Do
Loop
Loop
Case "DISPENSE"
Case DISPENSE
Print "Dispensing product... ";
Print "Dispensing product... ";
Print "Please (C)ollect product. : ";
Print "Please (C)ollect product. : ";
Do
Do
Do: KBD = Ucase(Inkey): Loop While KBD = ""
Do: KBD = Ucase(Inkey): Loop While KBD = ""
If KBD = "C" Then state = "READY" : Exit Select
If KBD = "C" Then state = READY : Exit Do
Loop
Loop
Case "REFUND"
Case REFUND
Print "Please collect refund."
Print "Please collect refund."
state = "READY"
state = READY
KBD = " "
KBD = " "
Case "QUIT"
Case QUIT
Print !"Thank you, shuttingwn now.\n"
Print !"Thank you, shuttingwn now.\n"
Exit Do
Exit Do
Line 595: Line 604:
Igual que la entrada de Phix.
Igual que la entrada de Phix.
</pre>
</pre>



=={{header|Go}}==
=={{header|Go}}==