WHILE, BREAK and CONTINUE Statements in SQL - ByteScout
  • Home
  • /
  • Blog
  • /
  • WHILE, BREAK and CONTINUE Statements in SQL

WHILE, BREAK and CONTINUE Statements in SQL

WHILE keyword loops statement inside it, until condition specified by it satisfies. There are often chances for WHILE loop to go into an infinite loop, so we have to make sure to update necessary variables if any inside while block.

Its syntax is very simple, as listed BELOW.

Keyword CONTINUE is used if want to skip the rest of the statements in the WHILE loop and go directly to the condition evaluation part. BREAK keyword stops further execution and exits while loop.

 

It’s said one practice is better than 100 theories. So let’s take a practical approach now:

Challenge: Print all odd numbers between 1 and 10.

The solution is here.

 

In conclusion, a WHILE loop runs a code section continually until a defined situation is no longer accurate. Now, in the loop section, the implementation can be handled with the BREAK and CONTINUES conditions. BREAK forces a withdrawal from the loop and CONTINUE forces the loop to continue and proceed to the subsequent iteration. In other words, The break message ends a while or for loop entirely. The continue message ends the performance of the conditions within a while or for loop and continues the loop in the next iteration.

   

About the Author

ByteScout Team ByteScout Team of Writers ByteScout has a team of professional writers proficient in different technical topics. We select the best writers to cover interesting and trending topics for our readers. We love developers and we hope our articles help you learn about programming and programmers.  
prev
next