formin1234;doecho"values is $m"donefornin This is a dong;doecho$ndone
while 语句
while 循环语法格式
int=5while(($int>=2));doecho"$int"let"int--"doneecho"按下CTRL+D退出"echo"输入你喜欢的电影"whileread film;doecho"${film} is ok"done
无限循环
while True;doecho"ok"donefor((::))
until循环
until 循环执行一系列命令直至条件为 true 时停止
a=0until[!$a-lt10];doecho$aa=$((a+1))done
case … esac
echo"输入1到4之间的数字"read-p"数字:" num
case$numin1)echo'1';;2)echo'2';;3)echo'3';;4)echo'4';;esacs1='iambot'case$s1in'iambot')echo'bot';;'iampm')echo'pm';;'iampl')echo'pl';;esac
跳出循环
break 命令允许跳出所有循环
echo"welcome to Amusement park"echo"please inter a number between 1-4"while:doread-p"please inter your number: " numcase$numin1|2|3|4)echo"you choose 1-4 you are great";;*)echo"you choose others you are bad"break;;esacdone
continue 命令不会跳出所有循环,仅仅跳出当前循环。
echo"welcome to Amusement park"echo"please inter a number between 1-4"while:doread-p"please inter your number: " numcase$numin1|2|3|4)echo"you choose 1-4 you are great";;*)echo"you choose others you are bad"continueecho'game over';;esacdone#运行代码发现,当输入大于5的数字时,该例中的循环不会结束,语句 echo "游戏结束" 永远不会被执行。