Usage and difference of the continuebreakreturn function-PHP source code

Source: Internet
Author: User
Ec (2); * $ i5; & nbsp; copy the code $ sum0; for ($ j0; $ j & lt; 10; $ j ++) {& nbsp; if ($ j $ I) & nbsp ;{& nbsp; & nbsp; break; & nbsp ;}& nbsp; else & nbsp ;{& nbsp; & nbsp; $ sum + $ j; & nbsp;} script ec (2); script

*/
$ I = 5;

The Code is as follows:
$ Sum = 0;
For ($ j = 0; $ j <= 10; $ j ++)
{
If ($ j = $ I)
{
Break;
}
Else
{
$ Sum + = $ j;
}
}

Echo $ sum; // 10

The Code is as follows:
$ ContinueSum = 0;
For ($ I = 0; $ I <= 10; $ I ++)
{
If ($ I = 5)
{
Continue;
}
Else
{
$ ContinueSum + = $ I;
}
}
The Code is as follows:

Echo $ continueSum; // 50


$ A = 2;


If ($ a = 2)
{
Return $ s = 8;
}
Else
{
Return $ s = 9;
}


Echo $ s; // nothing. Let's write it as a function.


Echo sv ($ a); // lost 10

The Code is as follows:
Function sv ($)
{
If ($ a = 2)
{
Return 10;
}
Else
{
Return 11;
}
}

/*
Summary:
Continue jumps out of the current loop and enters the next loop
The break jumps out of the current loop and executes other code.
The return operation is terminated, and no code after the return operation is executed.
The original article on this site is reprinted with the source www.111cn.net/phper/php.html
*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.