CONTINUE
CONTINUE is a Transact-SQL statement that is used within WHILE loops. Its function is to immediately jump to the start of the loop, allowing the execution sequence to bypass the rest of the loop's code block and begin the next iteration.
Example
Output
Explanation
In the above example, a loop runs ten times, printing numbers from 1 to 10. However, when the number is 5, the CONTINUE
statement is encountered. This causes the control to go back to the start of the loop, skipping the print statement for the number 5. Thus, the output doesn’t include 5.
Example
Output
Explanation
The CONTINUE
keyword in SQL Server is used to start the next iteration of a loop, skipping any subsequent statements in the current iteration. In the provided example, a WHILE
loop is used to iterate over integer values from 1 to 10. When the integer value is equal to 5, the CONTINUE
keyword skips the print statement for the current iteration, resulting in the value 5 being omitted from the output.