CONTINUE
Example
Section titled “Example”DECLARE i number := 1;BEGIN WHILE i <= 10 LOOP IF i = 5 THEN i := i + 1; CONTINUE; END IF; dbms_output.put_line(i); i := i+1; END LOOP;END;Output
Section titled “Output”1234678910Explanation
Section titled “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
Section titled “Example”DECLARE @Num INT;SET @Num = 1;
WHILE @Num <= 10BEGIN IF @Num = 5 CONTINUE;
PRINT @Num;
SET @Num = @Num + 1;ENDOutput
Section titled “Output”1234678910Explanation
Section titled “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.