Converting an if-else statement into a switch statement <p>I'm having trouble turning this program from an if-else statement into a switch statement. Any help would be appreciated.</p> <pre><code>#!/bin/bash for x in $@ do array[$i]=$x i=$((i+1)) done # initial state state=S0 for((i=0;i&lt;${#array[@]};i++)) do if [ $state == S0 ] then if [ ${array[$i]} == I0 ] then state=S1 output[$i]=O1 elif [ ${array[$i]} == I1 ] then state=S0 output[$i]=O0 fi elif [ $state == S1 ] then if [ ${array[$i]} == I0 ] then state=S1 output[$i]=O1 elif [ ${array[$i]} == I1 ] then state=S0 output[$i]=O0 fi fi done echo "final state="$state echo "output="${output[@]} </code></pre> <p>for those who are wondering about script.. this script about finite state machine .. this script has two states I want to convert to case statement so it can be readable and faster especially for big projects not like this one.</p>