Low cost ecommerce web development India flash website design 

Control Structures

Control structures allow you to control the flow of execution of your scripts.

You can specify that some code should be executed only under certain

circumstances, using conditional structures. You can specify that some code

should be executed repeatedly, using looping structures. Lastly, you can

specify that code from somewhere else in the script should be executed using

branching controls.

Conditional Structures

The If...Then...Else construct allows you to choose which block of code to

execute based on a condition or series of conditions.

<%

If condition1 Then

codeblock1

ElseIf condition2 Then

codeblock2

Else

49

codeblock3

End If

%>

If condition1 is true, codeblock1 is executed. If it is false, and condition2 is

true, codeblock 2 is executed. If condition1 and condition2 are both false,

codeblock3 executes. An If-Then construct may have zero or more ElseIf

statements, and zero or one Else statements.

In place of some really complex If ...Then constructs, you can use a Select

Case statement. It takes the following form:

Select Case variable

Case choice1

codeblock1

Case choice2

codeblock2

Case choicen

codeblockn

Case default

default code block

End Select

This compares the value of variable with choicel, choice2, and so on. If it

finds a match, it executes the code associated with that choice. If it does not, it

executes the default code.

Looping Structures

Looping structures allow you to execute the same block of code repeatedly.

The number of times it executes may be fixed or may be based on one or

more conditions.

The For...Next looping structure takes the following form:

For counter = start to stop

codeblock

Next

codeblock is executed with counter having the value start, then with counter

having the value start+1, then start+2, and so forth through the value stop.

Optionally, you may specify a different value to increment counter by. In this

case the form looks like this:

For counter = start to stop Step stepvalue

codeblock

Next

Now counter will take the values start+stepvalue, start+stepvalue+stepvalue,

and so forth. Notice that if stepvalue is negative, stop should be less than start.

50

The For Each...Next looping structure takes the following form:

For Each item In Set

codeblock

Next

codeblock is executed with item taking the value of each member of Set. Set

should be an array or a collection.

The Do While-Loop looping structure has the following form:

Do While booleanValue

code block

Loop

codeblock is executed as long as booleanValue is True. If it is False to begin

with, the loop is not executed at all.

The While...Wend looping structure has the following form:

While booleanValue

codeblock

Wend

codeblock is executed as long as booleanValue is True. If it is False to begin

with, the loop is not executed at all.

The Do-Loop While looping structure has the following form:

Do

code block

Loop While booleanValue

codeblock is executed as long as booleanValue is True. The loop is executed

at least once no matter what.

The Do Until-Loop looping structure has the following form:

Do Until booleanValue

codeblock

Loop

code block is executed as long as booleanValue is false. If it is true to begin

with, the loop is not executed at all.

The Do...Loop Until looping structure has the following form:

51

Do

code block

Loop Until booleanValue

code block is executed as long as booleanValue is false. The loop is executed

at least once no matter what.

Branching Structures

Branching structures allow you to jump from one position in the code to

another. A subroutine does not return a value. It simply executes. Subroutines

look like this:

Sub name (argumentlist)

code block

End Sub

Functions do return values and have the following form:

Function name (argumentlist)

code block

name = expression

End Function

freelance web designer India web development

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73