Function fsmHeater()
Dim Timer As Integer 'Initialize
State0:
Off (oHeater)
Off (oAlarm)
'---
WaitFor(Temperature() < 84)
State1:
On (oHeater)
Timer = GetmS()
'---
Select Event
Event Temperature() > 85
GoTo State0
Event GetmS() - Timer > 6000
GoTo State2
EndSelect
State2:
Off (oHeater)
On (oAlarm)
'---
WaitFor(Input(iResetButton))
GoTo State0
End Function
[/source]
Is this a good use of GoTo? This code is supposed to mimic a FSM. Personally, I see nothing wrong with it. Given the function is pretty short. But I wonder if this approach should be avoided: because of a better solution, or just because GoTo is the spawn of evil itself.
FSM Link
A snippet from page:
Notice that when an event match happens the line of code following the event condition is executed. In this program that is a GoTo. In many circles GoTo is considered to be bad programming. Not so in coding FSMs; GoTo allows you to move from place to place in the code in a way that echoes how the state diagram transitions from place to place. [/quote]