continue 使用

这是一个很精典的例子.这是跳出.跟跳出循环.在你输入1-5选择输入.打印出你选择的是1-5之间的数字.如果你选择超过5或是其他任意值.那么会跳到下个循环Wrong number,continue (y/n),问你是否要续继.这样不断的循环.

#breakout
while :
do
        echo -n “Enter any number [1...5]:”
        read ANS
        case $ANS in
        1|2|3|4|5)
                echo “you enter a number between 1 and 5!”
                ;;
        *)
                echo -n “Wrong number,continue (y/n)?:”
                read IS_CONTINUE
                case $IS_CONTINUE in
                 y|yes|Y|Yes)
                        continue
                        ;;
#这个就是定义跳出循环跟跳回到循环当中.只有输入Y/yes,才能跳回循环中.如果是N/no或是任意值都跳出这个循环.

                 *)
                        break
                        ;;
                esac
        esac
done

原创文章,转载请注明: 转载自PT Ubuntu Blog

本文链接地址: http://www.ptubuntu.com/2008/11/558.html

Share

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Verify Code   If you cannot see the CheckCode image,please refresh the page again!