Home | » | ASP | » | VBScript Looping Logic |
A Computer is used for performing many Repetitive types of tasks The Process of Repeatedly performing tasks is known as looping The Statements in the block may be Executed any number of times from Zero to Up to the Condition is True The Loop is that in which a task is repeated until the condition is true or we can say in the loop will Executes all the statements are until the given condition is not to be false. These are generally used for repeating the statements. In this There is Either Entry Controlled loop or as Exit Controlled Loop We know that before Execution of Statements all Conditions are Checked these are Performed by Entry Controlled Loops Which First Checks Condition And in Exit Controlled Loop it Checks Condition for Ending Loop Whether given Condition is False or not if a Loop First Checks Condition For Execution then it is called as Entry Controlled Loop and if a Loop Checks Condition after the Execution of Statement then they are Called as Exit Controlled Loops.
In The loop generally there are three basic operations are performed
1) Initialization
2) Condition check
3) Increment
There are the four types of loops in the vcbscript
1) while
2) do-while
3) for
4) For-Each
all these are used for performing the repetitive tasks until the given condition is not true.
While...Wend Statements
While Loop is Known as Entry Controlled Loop because in The while loop first we initialize the value of variable or Starting point of Execution and then we check the condition and if the condition is true then it will execute the statements and then after it increments or decrements the value of a variable. But in the While loop if Condition is false then it will never Executes the Statement and Always Remember while Loop is always Ends with the Wend statement .
Example: 5 While Wend Statements
Do While...Loop Statements
This is Also Called as Exit Controlled Loop we know that in The while loop the condition is check before the execution of the program but if the condition is not true then it will not execute the statements so for this purpose we use the do while loop in this first it executes the statements and then it increments the value of a variable and then last it checks the condition So in this either the condition is true or not it Execute the statement at least one time. Do while loop is always ends with loop Keyword.
Example: 6 Do While...Loop Statements
Do Until...Loop Statements
Do until Loop is also another type of Loop that is provided by Vb Script and this loop also performs repetitive types of tasks This is must similar to do While Loop but Only Difference in this it Executes the Statements until the Condition is true and not becomes false and do until loop is also ends with the loop keyword.
Example: 7 Do Until...Loop Statements
For...Next Statements
For In This loop all the basic operations like initialization, condition checking and incrementing or decrementing all these are performed in only one line. This is similar to the while loop for performing its execution but only different in its syntax. In this increment is given by using step Keyword but if you doesn't provide a step value then the default increment will be one and if you wants to decrease the value of variable by one then you have to specify the step value with -1 For Loop is always Closed with Next Keyword.
Example: 8 For...Next Statements
For Each...Next Statements
For Each loop is also similar to For loop but For Each loop Works on group of Items like Arrays and Collection objects this will contains all the Elements of an object one by one and For Each loop is also Closed with Next Keyword.
Infinite Loops
If there is nothing in your block that will eventually cause condtion to be False. the code will execute indefinitely. This is called an infinite loop and will make visitors to your page very unhappy.
Example: 10 Infinite Loops
Nesting Loops
When a for statment is executed within another for statement, then it is called nested for statement. We can apply number of nested for statement in VBScript.
Example: 11 Nesting Loops
Blogger Comment
Facebook Comment