Chapter 5. Control of Flow

The VBScript language provides certain mechanisms to allow you to manipulate the execution of the code in your script. For example, you can use branching logic to skip some lines of code. You can also execute some lines of code multiple times through the use of looping logic. The common term for the way in which you use these techniques is called control of flow.

Branching logic is implemented in VBScript with statements such as If, Else, and Select Case. Loops are defined with the For, Do, and While blocks. The sections in this chapter prepare you with all of the information you need on branching and looping, which are as essential to programming as variables. If you are relatively new to programming, this is an important chapter. Like all of the chapters up to this point, this chapter explains essential programming fundamentals while also teaching you the VBScript-specific techniques and syntax.

If you are an experienced programmer in another language, you might only skim this chapter for some of the VBScript particulars. VBScript's branching and looping capabilities are basically the same as any mature procedural language, and are virtually identical to Visual Basic's. If you are looking only for syntax details, the language reference in Appendix A might be your best source of information.

Branching Constructs

Branching is the process of making a decision in your code and then, based on that decision, executing one block of code, but not others. If you ...

Get VBScript Programmer's Reference, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.