php中跳出函数break,continue,exit的使用与区别
Jun 12, 2016 pm 08:07 PM
breakcontinuephpcodeOpen sourceprogrammingprogramming languagesoftware development
1.break跳出代码片段,结束这个循环
2.continue结束当前片段,结束这次循环,继续下一次循环
3.exit 结束整个PHP代码
<span style="font-family: tahoma, arial, helvetica, sans-serif; font-size: 14px;"><span style="line-height: 19px;">break的作用是跳出这个循环(如果这个break或者continue在循环中的if语句里面,不是跳出if语句,而是跳出循环语句),</span><span style="line-height: 19px;">执行这个循环的大括号以后的语句,</span></span>
<span style="font-family: tahoma, arial, helvetica, sans-serif; font-size: 14px;"><span style="line-height: 19px;">break在循环语句中是这样,在switch语句用功能也是这样的,而continue是当条件满足的时候不执行这个循环后面的语句,从这个循环的开始重新执行。</span></span>
<?php /* php的break,continue,return 的简单区别代码 */ $i = 1; while (true) { // 这里看上去这个循环会一直执行 if ($i==2) {// 2跳过不显示 $i++; continue; } else if ($i==5) {// 但到这里$i=5就跳出循循环了 break; } else { echo $i . '<br>'; } $i++; } exit; echo '这里不输出'; ?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks agoByDDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks agoByDDD
Assassin's Creed Shadows - How To Find The Blacksmith And Unlock Weapon And Armour Customisation
1 months agoByDDD
Where to find the Crane Control Keycard in Atomfall
3 weeks agoByDDD
Roblox: Dead Rails - How To Complete Every Challenge
3 weeks agoByDDD

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1
Easy-to-use and free code editor