Page 202 - DCAP408_WEB_PROGRAMMING
P. 202

Web Programming




                    Notes          Finally, _VBScript also allows the Step keyword to modify the interval or step-size of the For-
                                   loop variable.
                                          <%
                                          For  I  =  1  to  10  Step  2
                                          Response.Write  “Number  =  “  &  I  &  vbCrLf
                                          Next
                                          %>
                                   gives you:

                                          Number  =  1
                                          Number  =  3
                                          Number  =  5
                                          Number  =  7
                                          Number  =  9
                                   The loop counted I in steps of 2, thus taking on only odd values from the entire set of 10.
                                   For Each Object In Collection ...
                                   The For-Each construct is unique to _VBScript (and its parent, Visual Basic, of course!) It allows
                                   you to iterate through the items in a collection one by one.
                                          <%
                                          For  Each  Member  in  Team
                                          Response.Write  Member
                                          Next
                                          %>
                                   Here, Team is assumed to be a collection of items. This statement is very useful in scenarios,
                                   where the size of the collection is not known in advance. Using the For Next statement assures
                                   that all items in that collection will be processed, and no “Array Index Out Of Bounds” errors
                                   will be generated.

                                   While ... Wend

                                   Again, here is one of the popular looping constructs of all time.

                                          <%
                                          While  Not  RS.EOF
                                          Response.Write  RS.Fields  (“Name”)
                                          RS.MoveNext
                                          Wend
                                          %>
                                   or,
                                          <%
                                          Do  While  Not  RS.EOF
                                          Response.Write  RS.Fields  (“Name”)
                                          RS.MoveNext



          196                               LOVELY PROFESSIONAL UNIVERSITY
   197   198   199   200   201   202   203   204   205   206   207