Jump to content

Finite state machine: Difference between revisions

(→‎On browser using blocking window methods: How could I let this happen)
Line 1,278:
Press D (deposit) or Q (quit) and Enter</pre>
 
=={{header|VBA}}==
{{trans|Phix}}
<lang vb>Enum states
READY
WAITING
DISPENSE
REFUND
QU1T
End Enum '-- (or just use strings if you prefer)
Public Sub finite_state_machine()
Dim state As Integer: state = READY: ch = " "
Do While True
Debug.Print ch
Select Case state
Case READY: Debug.Print "Machine is READY. (D)eposit or (Q)uit :"
Do While True
If ch = "D" Then
state = WAITING
Exit Do
End If
If ch = "Q" Then
state = QU1T
Exit Do
End If
ch = InputBox("Machine is READY. (D)eposit or (Q)uit :")
Loop
Case WAITING: Debug.Print "(S)elect product or choose to (R)efund :"
Do While True
If ch = "S" Then
state = DISPENSE
Exit Do
End If
If ch = "R" Then
state = REFUND
Exit Do
End If
ch = InputBox("(S)elect product or choose to (R)efund :")
Loop
Case DISPENSE: Debug.Print "Dispensing product..."
Do While True
If ch = "C" Then
state = READY
Exit Do
End If
ch = InputBox("Please (C)ollect product. :")
Loop
Case REFUND: Debug.Print "Please collect refund."
state = READY
ch = " "
Case QU1T: Debug.Print "Thank you, shutting down now."
Exit Sub
End Select
Loop
End Sub</lang>{{out}}
<pre>Machine is READY. (D)eposit or (Q)uit :
D
(S)elect product or choose to (R)efund :
S
Dispensing 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|zkl}}==
A lame FSM, we just convert text to a [hopefully valid] zkl program, compile and run it.
255

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.