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. CentOS 6.5配置nfs服务

    CentOS 6.5配置nfs服务 网络文件系统(Network File System,NFS),一种使用于分散式文件系统的协议,由升阳公司开发,于1984年向外公布.功能是通过网络让不同的机器.不 ...

  2. 【转】git与github在ubuntu下的使用 -- 不错

    原文网址:http://www.cnblogs.com/cocowool/archive/2010/10/19/1855616.html 最近开始使用git对kohana3的文档做一些补充的工作,使用 ...

  3. HDOJ-1015 Safecracker(DFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=1015 题意:给出一个目标值target和一个由大写字母组成的字符串 A-Z分别对应权值1-26 要求从给出的字符 ...

  4. softlayerFastUploadVHDtoBS

    Object Storage Uploader Overview We’ve recently added the option to import customer-supplied Virtual ...

  5. Java日志终极指南

    Java日志基础 Java使用了一种自定义的.可扩展的方法来输出日志.虽然Java通过java.util.logging包提供了一套基本的日志处理API,但你可以很轻松的使用一种或者多种其它日志解决方 ...

  6. Uboot与Linux之间的参数传递

    U-boot会给Linux Kernel传递很多参数,如:串口,RAM,videofb等.而Linux kernel也会读取和处理这些参数.两者之间通过struct tag来传递参数. U-boot把 ...

  7. iTunes 重新提交代码步骤

    1.选择View Details 2.右侧Links-Binary Details选项 3.Reject This Binary

  8. SQL Server,Oracle,DB2索引建立语句的对比

    原文引至:http://jvortex.blog.163.com/blog/static/16961890020122141010878/ 我们知道,索引是用于加速数据库查询的数据库对象.原理就是减少 ...

  9. XTU OJ 1209 Alice and Bob 2014(嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛)

    Problem Description The famous "Alice and Bob" are playing a game again. So now comes the ...

  10. 常用LINUX脚本汇总(1)

    1.查看磁盘使用空间 df -hl 2.查看文件或者文件夹大小 du -sh 文件(夹)名  查看文件大小  AIX系统为du -sg 3.查看当前用户下定时任务列表crontab -l 4.修改定时 ...