zjzc01:/root/test# cat a3.pl
sub mask {
my $n=shift;
my $j =100;
for ($i = 1;$i <= 5;$i++){
print "\$i is $i\n";
while ($n=$n+1) {
$j++;
print "\$n is $n\n";
if ($n==10){print "\$n---end is $n\n";$n=0;last};
}}
}; &mask(1);
zjzc01:/root/test# perl a3.pl
$i is 1
$n is 2
$n is 3
$n is 4
$n is 5
$n is 6
$n is 7
$n is 8
$n is 9
$n is 10
$n---end is 10
$i is 2
$n is 1
$n is 2
$n is 3
$n is 4
$n is 5
$n is 6
$n is 7
$n is 8
$n is 9
$n is 10
$n---end is 10
$i is 3
$n is 1
$n is 2
$n is 3
$n is 4
$n is 5
$n is 6
$n is 7
$n is 8
$n is 9
$n is 10
$n---end is 10
$i is 4
$n is 1
$n is 2
$n is 3
$n is 4
$n is 5
$n is 6
$n is 7
$n is 8
$n is 9
$n is 10
$n---end is 10
$i is 5
$n is 1
$n is 2
$n is 3
$n is 4
$n is 5
$n is 6
$n is 7
$n is 8
$n is 9
$n is 10
$n---end is 10 last 是退出当前循环 zjzc01:/root/test# cat a3.pl
sub mask {
my $n=shift;
my $j =100;
for ($i = 1;$i <= 5;$i++){
print "\$i is $i\n";
while ($n=$n+1) {
$j++;
print "\$n is $n\n";
if ($n==10){print "\$n---end is $n\n";$n=0;return};
}}
}; &mask(1);
zjzc01:/root/test# perl a3.pl
$i is 1
$n is 2
$n is 3
$n is 4
$n is 5
$n is 6
$n is 7
$n is 8
$n is 9
$n is 10
$n---end is 10 return是退出当前函数 退出循环是break
return是退出函数并返回, 如果函数有返回值,可以将返回值返回

perl return和break的更多相关文章

  1. return、break、continue的区别

    一.定义 return:语句用于终止当前方法运行,返回到调用该方法的语句处.如有返回值,则在return后面提供相应的返回值. break:其主要用于循环语句和switch语句,其作用均是强行终止语句 ...

  2. return和break的区别

    /* Name:return和break的区别 Copyright: By.不懂网络 Author: Yangbin Date:2014年2月25日 02:13:22 Description:以下代码 ...

  3. php 中 return exit break contiue 详解

    return.break和contiue是语言结构,就如同if语句之类的,但是exit却是个函数. 1.exit函数 作用:Output a message and terminate the cur ...

  4. php exit、return、break、continue之间的差别,具体介绍

    相信大家在php开发中有几个经常使用的停止程序和循环的keyword的误区( exit.return.break.continue) exit 退出全部脚本,是个函数 return 语言结构的使用方法 ...

  5. return、break和continue

    return.break和continue 这三个关键字有一个共同点,那就是读能让后面的语句不执行,不同的地方就是挑的距离不一样. return很强大,如果一个函数中有一个return,并且执行了,那 ...

  6. return false break;

    js中的return false;  break; , , , , ]; var list2 = ['a', 'b', 'c', 'd']; ; j < list2.length; j++) { ...

  7. Return 和 Break 的区别

    前段日子发布的负面情绪太多了,哦哦,其实我需要的是努力,努力提高自己的真实能力.经历了好多的鄙视否定,我已经没有最初那么敏感,心态平和了许多.我没有借口说基础不好了,一年了,要努力的话,那么我应该不会 ...

  8. MATLAB中return和break

    return: RETURN Return to invoking function. RETURN causes a return to the invoking function or to th ...

  9. return及break区别

    一.break 语句 中止当前循环,switch 语句或 label 语句,并把程序控制流转到紧接着被中止语句后面的语句. 示例 下面的函数里有个 break 语句,当 i 为 3 时,会中止 whi ...

随机推荐

  1. Longest Valid Parentheses 解答

    Question Given a string containing just the characters '(' and ')', find the length of the longest v ...

  2. Android应用开发学习之状态栏通知

    作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 状态栏通知涉及到两个类,一是Notification,它代表一个通知:另一个是NotificationManager ...

  3. [转]Google2012.9.24校园招聘会笔试题

    代码: [cpp] view plaincopy //转载请标明出处,原文地址:http://blog.csdn.net/hackbuteer1/article/details/8017703 boo ...

  4. 程序员求职之道(《程序员面试笔试宝典》)之看着别人手拿大把的offer,不淡定了怎么办?

    不管是在哪里,不管发生什么事,不要随便放下自己. --<当男人恋爱时> 很多求职者都会面临一个问题:别人手拿大把大把的offer了,而自己却是两手空空,别人签约之后已经过着"猪狗 ...

  5. JVM结构、GC工作机制详解

      JVM结构.内存分配.垃圾回收算法.垃圾收集器.下面我们一一来看. 一.JVM结构 根据<java虚拟机规范>规定,JVM的基本结构一般如下图所示: 从左图可知,JVM主要包括四个部分 ...

  6. iOS开发之Crash分析,以及收集

    一  先谈谈iOS的Crash收集方式: 1. APP 发生crash,用户手机手机上肯定会有crash纪录,当然删除了该app,或是删了再装 crash纪录还是没了. 2. 如果用户设置-隐私  同 ...

  7. 给SharePoint页面加入自己定义页脚Custom footer

    给SharePoint页面加入自己定义页脚Custom footer         在公司做站点设计项目时,须要在页面上加入页脚.         非常多人都把页脚忽视了,认为没什么多大用处,事实上 ...

  8. POJ 1987 BZOJ 3365 Distance Statistics 树的分治(点分治)

    题目大意:(同poj1741,刷一赠一系列) CODE: #include <cstdio> #include <cstring> #include <iostream& ...

  9. iOS:UI系列之UIScrollview和UIPagecontrol

    转眼间,又是一天,就这样忙忙碌碌的一天一天的过着, 不过还好,不是浑浑噩噩的,也算是小有所成,劳有所获吧,嘿嘿! 好了,到了总结的时间啦, 下面就为大家简单讲解下我今天学习的内容吧,希望对各位都有所帮 ...

  10. Android-----------国际化多国语言文件夹命名汇总

    *如果不区分地区,则不加后面的-rxx内容 Arabic, Egypt (ar_rEG) —————————–阿拉伯语,埃及      Arabic, Israel (ar_rIL) ———————— ...