U
utauta
Guest
I'm using a state machine for a simple project and wanted to know if I
can create a state machine within a function in order to shorten code.
For example: If I have 6 different input combinations and need to go
through the same sequence of states except for a few small
modifications pertaining to input values.
Long version:
if (input 1)
state 1 > state 2 > state custom, state 4, state 5, state 6
elsif (input 2)
state 1 > state 2 > state custom, state 4, state 5, state 6
elsif (input 3)
state 1 > state 2 > state custom, state 4, state 5, state 6
elsif (input 4)
state 1 > state 2 > state custom, state 4, state 5, state 6
end if;
Short version:
function(argument):
state 1 > state 2 > state custom, state 4, state 5, state 6
end function
if (input 1)
function(argument 1)
elsif (input 2)
function(argument 2)
elsif (input 3)
function(argument 3)
elsif (input 4)
function(argument 4)
end if;
What is the best way to implement this?
can create a state machine within a function in order to shorten code.
For example: If I have 6 different input combinations and need to go
through the same sequence of states except for a few small
modifications pertaining to input values.
Long version:
if (input 1)
state 1 > state 2 > state custom, state 4, state 5, state 6
elsif (input 2)
state 1 > state 2 > state custom, state 4, state 5, state 6
elsif (input 3)
state 1 > state 2 > state custom, state 4, state 5, state 6
elsif (input 4)
state 1 > state 2 > state custom, state 4, state 5, state 6
end if;
Short version:
function(argument):
state 1 > state 2 > state custom, state 4, state 5, state 6
end function
if (input 1)
function(argument 1)
elsif (input 2)
function(argument 2)
elsif (input 3)
function(argument 3)
elsif (input 4)
function(argument 4)
end if;
What is the best way to implement this?