PHP函数continue在循环结构中的用法
2013-09-04 21:48
281 查看
我们在实际的PHP函数continue与众不同之处在于接受一个可选的数字参数来决定跳过几重循环到循环结尾。
在php中,continue 在循环结构中用来跳过本次循环中剩余的代码并开始执行下一次循环。这一点和其他语言是一致的,不过,另有妙处:continue 接受一个可选的数字参数来决定跳过几重循环到循环结尾。
#php_continue.php $i = 0; $j = 0; while ($i++ <3) {//level 3 echo "Outer n"; while (1){//level 2 echo "Middle n"; while (1){//level 1 echo "Inner n"; continue 3; } echo "Thisnever gets output. n"; } echo"Neither does this. n"; $j++; //after runscontinue 3,it comes to the end of level 3 } echo"$j=$j";//output: $j=0 ?> 以上这段代码,就是PHP函数continue的具体用法,希望对大家有所帮助。
在php中,continue 在循环结构中用来跳过本次循环中剩余的代码并开始执行下一次循环。这一点和其他语言是一致的,不过,另有妙处:continue 接受一个可选的数字参数来决定跳过几重循环到循环结尾。
#php_continue.php $i = 0; $j = 0; while ($i++ <3) {//level 3 echo "Outer n"; while (1){//level 2 echo "Middle n"; while (1){//level 1 echo "Inner n"; continue 3; } echo "Thisnever gets output. n"; } echo"Neither does this. n"; $j++; //after runscontinue 3,it comes to the end of level 3 } echo"$j=$j";//output: $j=0 ?> 以上这段代码,就是PHP函数continue的具体用法,希望对大家有所帮助。
相关文章推荐
- 控制结构--for循环和while循环的特殊用法、continue语句及break语句的用法
- JS中continue在while循环、do-while循环以及for循环中的用法
- java循环结构(以及break,continue的使用)
- python中的循环与break和continue的关系和用法
- 循环 语句 break的用法 continue的用法
- 循环结构中break、continue、return和exit的区别
- java循环结构中break、continue、return的区别及使用情景
- 循环结构中break、continue、return和exit的区别
- 循环结构中break、continue、return和exit的区别
- 循环结构中break、continue、return和exit的区别
- 循环结构中break、continue、goto、return和exit的区别
- 循环结构中break、continue、return和exit的区别
- java的选择结构switch和循环结构for while do while以及流程控制语句break continue return
- JavaSE007_循环结构之continue
- 黑马程序员----C语言学习笔记之循环结构介绍和用法举例
- 循环语句中的break、continue、return用法
- 循环结构中break、continue、return和exit的区别
- break,continue在循环语句中的具体用法
- 循环名标签+break、continue控制内外层循环结构
- Python循环语句之break与continue的用法