SQL While loop statement continue back to loop start/break jump loop

Source: Internet
Author: User

CONTINUE back to loop start/BreakJump out of the loop.
The following is a simple example:

1>DECLARE
2> @testvalueAsINT;
3> BEGIN
--Set Variable initial value = 0
4> SET @testvalue = 0;
--When the variable is less than 5 cycles
5>While@testvalue < 5
6> BEGIN
--Variable increment
7> SET @testvalue = @testvalue + 1;

--if the variable = 2, then return to the beginning of the loop
8>IF@testvalue = 2
9> BEGIN
10> CONTINUE;
11>END;

--if the variable = 4, then jump out of the loop
12>IF@testvalue = 4
13> BEGIN
14>Break;
15> END;

--Print variable contents
16>PRINT(@testvalue);
17> END
18> END;
19> Go

This article is from the "7240173" blog, please be sure to keep this source http://wwdyl.blog.51cto.com/7240173/1731822

SQL While loop statement continue back to loop start/break jump loop

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.