0
我無法將此程序從if-else語句轉換爲switch語句。任何幫助,將不勝感激。將if-else語句轉換爲switch語句
#!/bin/bash
for x in [email protected]
do
array[$i]=$x
i=$((i+1))
done
# initial state
state=S0
for((i=0;i<${#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[@]}
爲那些誰知道有關腳本..這個腳本有關的有限狀態機..這個腳本有兩種狀態我要轉換爲case語句,因此它可以是可讀的,更快尤其是對大項目不是這樣一。
你有什麼麻煩? – chepner
請勿標記垃圾郵件。這與Linux,Emacs或SQL CASE語句無關。我刪除了無關標籤。 – Chris