|
|
|
|
|
|
|
Chapter 1: Using Loops and Conditionals
Chapter 3 introduces the conditional code execution and looping constructs provided by Visual Basic Script. These capabilities allow you to make decisions and execute blocks of code accordingly. Making a simple decision with If-Then The most common way to execute conditional code is with the If-Then statement. This example makes a simple decision and writes the appropriate text to the browser. (Note: This version includes fixes bugs found in the book). Page 27. JavaScript version Making a more complex decision with If-Then-Else and If-Then-ElseIf While the previous example works, it's not technically the best way to make more than one decision. This example introduces the Else and ElseIf clauses, which make multiple decisions more simple. Page 28. JavaScript version Using Select Case to make decisions VBScript provides an even more elegant way to make decisions, the Select Case statement, which is ideal for a long list of possible outcomes. Page 29. JavaScript version Looping with Do-Until Do Until is the simplest looping construct in VBScript. It allows you to execute code until a certain condition is met. Page 30. (no JavaScript version) Looping with Do-While The most versatile VBScript loop is Do While, which repeats a block of code while a certain condition is true. The example here is slightly different than that found in the book, reflecting the prefered way to use this construct. Page 31. JavaScript version Looping with While-Wend The Do-While loop's inbred step-brother, the While-Wend loop isn't used very often. I recommend Do-While instead. Page 32. JavaScript version Using the For-Next Loop The For-Next loop is easily the most widely used and recognized looping construct. Pages 33-34. JavaScript version |
|
|
| All content © 1997-1999 Paul Thurrott |