Page

5.3.4- Examples of Control Structures

  by NT Community Manager.
Last Updated  by Joel Bush.  

PublicCategorized as 05. ASP Control Structures.

Not tagged.
<< 5.3.3- Jumping ControlsChapter55.4.0- Branching Statements >>

Examples of Control Structures

With these three classes of controls – branching, jumping and looping – we can solve virtually any programming objective in ASP. In the table below we've listed several situations we might want to program for, and suggested which class of controls will help us achieve them.

 

Situation

Solution

Why?

I want ASP to show page A or page B.

Branching

We want to perform only one of two possible events.

I want ASP to list each member of the club. The data about each member is held in essentially the same manner, with a name, photo, address and other contact information.

Looping

We will be performing the same set of code (that retrieves a member's name) many times (once for each member, until we list all members).

I want to build a table.

Looping

We will perform the same code (make a row for a table) again and again until we have built all of the rows needed.

I need to calculate prices in several places on each page. The prices will be set according to input from a user form.

Call using a function

We will pause building the page, execute code to calculate the price of an item, then return to building the page. Since we will calculate many prices it is best to write the formula once and have it called when needed.

I need to show the user which of several meetings they should attend. The meeting displayed is based on which department they belong to.

Branching

We want to write to the page only one out of several possible meeting locations.

After every item that I describe in a catalog page, I want to put in a few lines of information about 'How to Order'.

Call using a subprocedure

We want to pause the main code and perform several lines of another set of code that describes 'How to Order'. Then we want to resume the main code. Since the 'How to Order' set of code will be performed at various times across the page, it is best to write it once and call that one piece of code as needed.

Let's recap on what we've discussed so far. There are three kinds of statements that control the flow of our code's execution:

 

  • Branching statements that perform a test and then execute some lines of code but not others
  • Looping statements that execute a set of code again and again
  • Jumping statements that pause the execution of the current code, jump over to another set of code, and then return

 

Now let's have a closer look at branching statements, and what we can do with them.

<< 5.3.3- Jumping ControlsChapter55.4.0- Branching Statements >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |