
|
|
|||
Decision Making and LoopingBy Amrit Hallan2005-06-01
Decision Making and Looping A common feature of any programming script/language is, its ability to perform repeat tasks until a condition is satisfied, and, its ability to take decision. After all, there can be no logic if a program cannot decide what to do and what not to do (sounds like a Shakespearean statement). Decision Making VBScript too can take if-then-else decisions. An example: <% Side Note: In the above program, we already know the values of num1 and num2, but if a user enters these values using an HTML form, then only this sort of program will be able to tell which value is greater. We can also check for multiple conditions, for instance, "if this is Jack's room and Jack is in the room and the room is in his house then Jack is at home." Programmatically: <% So for JackAtHome to be true, all preceding variables must be true too. So if we put an AND, all the conditions have to satisfy the "if" condition. If Jack can be at home if even one of the conditions is true, then we can have <% In case of an OR, any one of the conditions can satisfy an if structure. You can see that the if-then-else-end-if statement is almost similar to the real-world decision-making structure, and hence, is quite self-explanatory. Just take care that each if-then-else-end-if is properly indented, so that you can have multiple sub-if-then-else-end-if's without getting confused or bogged down. These are also called logical structure, for, if a and b are not equal, then some condition being a surely means that the condition is not b. Similar to if-then-else-end-if is the Select Case structure, which is much better organized then the if structures. Let's see how. (Note that whenever we have to insert remarks in the VBScript code, it is preceded by a single-quote.) <% Looping Many a time you have to perform a programming task again and again. For example, the program should keep reading the data rows of a database file until it encounters the end of the file. Or, a shopping cart script should keep adding items to the cart until the user clicks on "checkout" button. Primarily, in VBScript, there are four loop structures, namely, for…next, do…until…loop, while…wend, and do…while…loop. Let us see them one by one…continued on the next page. Tutorial Pages: » Decision Making and Looping » Decision Making and Looping...Continued
|
||||
| About the NetVisits, Inc Network | Write For Us | Advertise Copyright ©2007 NetVisits, Inc Network. All Rights Reserved. Privacy Policy. |
Visit other NetVisits, Inc. sites: |