ELSIF statements
Typically, in automation, a program will usually have multiple code blocks that will run under different situations. An example of this would be the state machines we explored with CASE
in the last chapter. Now, CASE
statements are excellent ways to build state machines and orchestrate multiple code blocks; however, they are not the only way. Another very common way of constructing something akin to a state machine is with the ELSIF
command.
When coupled with an IF
statement, ELSIF
will create a cohesive conditional block that will accommodate multiple conditions. For example, consider our beer discussion. If a person is in the United States, they must be at least 21 years old to purchase beer. On the other hand, if a person is in Mexico, they must only be 18 years old. If we needed a program that could handle this, we could use something like the following pseudocode:
Input age If country = "usa" then If age >= 21 then...