![]() Suppose you want to execute the block of code at least once regardless of the condition, then you can use Do While loop. If you assign the value 7 to the variable x at the beginning, then the code block will not be executed even once. So, while using Do While looping statements, you should make sure that there is some code that will make the looping condition true at one point or another. Infinite loops could even crash your system. ![]() This kind of loops is known as infinite loops. If you forget the statement x=x+1, then your loop will become a never-ending one. The block gets executed four times (when x=1,2,3 and 4) and the loop ends when the value of x becomes 5. If you try executing the code, you will get the output like this: In such case, Do While loop will be used. For example, you want to output the message “Welcome” while the value of the variable x is less than 5. If you do not know the number of times you need to execute a block of code, then you will be using Do While loops. Let’s take a look at these looping statements one by one. So based on whether you know or do not know the number of executions, you can use different types of looping statements.įor…Next looping statements are used if you want to repeat a block of code a finite number of times, that if you know the number of times if you want to repeat the block of code.ĭo While and Do Until looping statements are used when you want to repeat a block of code until a condition becomes true or false, that is when you are not aware of the number of times you want to execute the block of code. Here, you do not know how many times the loop is to be executed. Suppose, you want to calculate the sum of two numbers until a particular variable becomes true. ![]() In this case, you already know you want to repeat a block of code 10 times. For example, you want to calculate the sum of two numbers ten times. While executing the loops, you might or might not be aware of the number of times you want to execute a set of instructions. So, how will you decide which looping statement to use for your need? Some of the VBScript looping statements are Do While, Do Until, For….Next and so on. There are a number of VBScript looping statements. Loops are used to execute the same block of code again and again.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |