let's take another example where we will print the number in reverse order. In the example below we have used a the for loop to print numbers from 1 to 10. Let's see the for loop in action in the example below. Syntax: FOR counter_variable IN start_value.end_value LOOP The programmer need not have to write any instruction for incrementing or decrementing value. The for loop automatically increments the value of the counter variable by 1 at the end of each loop cycle. When we use the for loop we are supposed to define a counter variable which decides how many time the loop will be executed based on a starting and ending value provided at the beginning of the loop. This loop is used when some statements in PL/SQL code block are to be repeated for a fixed number of times. NOTE: You must write the code to increment the value of the variable that you put in the condition otherwise the value of the variable will remain the same and the condition will always remain true. Time for an Example!īelow we have a simple program to print the odd numbers between 1 to 10 using the while loop. Let's see the while loop in action in the code example below. It is an entry controlled loop which means that before entering in a while loop first the condition is tested, if the condition is TRUE the statement or a group of statements get executed and if the condition is FALSE the control will move out of the while loop. Let's take one more example where we will be using the exit when statement to break out of the loop. In the code below, we have used the loop to print counting from 1 to 10 on the console and have used the exit statement to break out of the loop. Let's see the simple loop in action in the code example below. A basic/simple loop can be terminated at any given point by using the exit statement or by specifying certain condition by using the statement exit when.Simple loop always begins with the keyword LOOP and ends with a keyword END LOOP.While using it, following two things must be considered: When we use the basic loop the code block will be executed at least once. PL/SQL Basic Loopīasic loop or simple loop is preferred in PL/SQL code when there is no surety about how many times the block of code is to be repeated. In this tutorial we will learn about all three of them while covering the concept of nexted loops which means loop inside a loop. In PL/SQL we have three different loop options to choose from when we want to execute a statement repeatedly in our code block. Loops in PL/SQL provides a way of repeating a particular part of any program or any code statement as many times as required.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |