perl return和break
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的更多相关文章
- return、break、continue的区别
一.定义 return:语句用于终止当前方法运行,返回到调用该方法的语句处.如有返回值,则在return后面提供相应的返回值. break:其主要用于循环语句和switch语句,其作用均是强行终止语句 ...
- return和break的区别
/* Name:return和break的区别 Copyright: By.不懂网络 Author: Yangbin Date:2014年2月25日 02:13:22 Description:以下代码 ...
- php 中 return exit break contiue 详解
return.break和contiue是语言结构,就如同if语句之类的,但是exit却是个函数. 1.exit函数 作用:Output a message and terminate the cur ...
- php exit、return、break、continue之间的差别,具体介绍
相信大家在php开发中有几个经常使用的停止程序和循环的keyword的误区( exit.return.break.continue) exit 退出全部脚本,是个函数 return 语言结构的使用方法 ...
- return、break和continue
return.break和continue 这三个关键字有一个共同点,那就是读能让后面的语句不执行,不同的地方就是挑的距离不一样. return很强大,如果一个函数中有一个return,并且执行了,那 ...
- return false break;
js中的return false; break; , , , , ]; var list2 = ['a', 'b', 'c', 'd']; ; j < list2.length; j++) { ...
- Return 和 Break 的区别
前段日子发布的负面情绪太多了,哦哦,其实我需要的是努力,努力提高自己的真实能力.经历了好多的鄙视否定,我已经没有最初那么敏感,心态平和了许多.我没有借口说基础不好了,一年了,要努力的话,那么我应该不会 ...
- MATLAB中return和break
return: RETURN Return to invoking function. RETURN causes a return to the invoking function or to th ...
- return及break区别
一.break 语句 中止当前循环,switch 语句或 label 语句,并把程序控制流转到紧接着被中止语句后面的语句. 示例 下面的函数里有个 break 语句,当 i 为 3 时,会中止 whi ...
随机推荐
- libeXosip2(2) -- General purpose API.
General purpose API. general purpose API in libeXosip2-4.0.0. More... Modules eXosip2 configuration ...
- Java Fuck Bignumber
为了熟悉java , 开一套poj大数处理的题来写. ------------------------------------------------------------------- A: (1 ...
- Python Cookie HTTP获取cookie并处理
Cookie模块同样是Python标准库中的一员,它定义了一些类来解析和创建HTTP 的 cookie头部信息. 一.创建和设置Cookie >>> import Cookie #导 ...
- 04747_Java语言程序设计(一)_第9章_输入和输出流
例9.1一个文件复制应用程序,将某个文件的内容全部复制到另一个文件. import java.io.*; public class Example9_1 { public static void ma ...
- Unity四种路径总结
四种路径的权限: Application.dataPath 包含游戏数据文件夹的路径(只读) Applicatio ...
- Gym Class(拓扑排序)
Gym Class Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- LeetCode——Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- SPOJ 1811 Longest Common Substring (后缀自动机第一题,求两个串的最长公共子串)
题目大意: 给出两个长度小于等于25W的字符串,求它们的最长公共子串. 题目链接:http://www.spoj.com/problems/LCS/ 算法讨论: 二分+哈希, 后缀数组, 后缀自动机. ...
- Qwt 折线图 波形图 柱状图示例效果
Qwt 目录下有不少 example,为了快速找到想要研究使用的例子,特意把所有例子的示例效果截图下来窗口标题即是 example 下的目录名称
- SAR ADC : 逐次逼近寄存器型(SAR)模数转换器(ADC)
1.为实现二进制搜索算法,N位寄存器首先设置在中间刻度(即:100... .00,MSB设置为1).这样,DAC输出(VDAC)被设为VREF/2,VREF是提供给ADC的基准电压.然后,比较判断VI ...