Lab4 - Lab 4 INT213 This lab will concentrate on looping...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab 4 - INT213 This lab will concentrate on looping structures. Like the Conditional (from last week), the loop allows our scripts to do things that would not be possible without them. In this case, to repeat some action(s) multiple times. Make sure you understand the concepts of Loops. They are vital not only in this course, but in other scripting courses in the CNS/CTY program. Loops Loops provide scripts with the ability to perform actions more than once. They are used to determine how many times an event occurs or to stop a scripts’ execution after a certain number of cycles. Used in conjunction with Conditional, loops become a powerful coding weapon. There are two main types of Loops: the For…Next and the and the Do loop. For …Next Loop This type of Loop is mainly used when the number of times the code should execute is known when the Loop begins. The structure of the For. ..Next loop is as follows; By default the counter will be increased by 1 each time the loop cycles. When the value of the counter is GREATER THAN the <End Number>, the loop will end. Here is a very basic For. ..Next Loop Save as INT213lab4a.asp <% Option Explicit Dim intcount 'set the loop to repeat 10 times For intcount = 1 to 10 'output something Response.Write "This is line# " & "<br>" Next %> OK, so all this loop did was to output the same line 10 times. This does not seem like a big deal, but imagine having to write out 10 Response.Write lines, instead of the 3 lines in the loop. As a note, the <Start Number> of the ‘For. ..Next’ loop does not have to start at 1. It can start at any number. Also, we can either “hard-code” the values for <Start Number> and <End Number>, as we did in INT213labs4a.asp, or use Variables in their place. The loop will convert the values in a Variable to use as the Start and End numbers. 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Do This Change the <Start Number> and <End Number> to anything you like and test the script again. Just make sure the <Start Number> is smaller than the <End Number> Questions 1) Since 'intcount' is a variable, how would you add the value of 'intcount' to the output of the Response.write line so that the output would include the line numbers? (Hint: Remember the ‘&’ ?) Write the Response.Write line to show this, then test it in INT213lab4a.asp _____________________________________________________________________________ 2) Change the <Start Number>, in INT213lab4a.asp , to 10 and the <End Number> to 1. Run the script. What Happened? And how can you Fix that? ______________________________________________________________________ ______________________________________________________________________ Changing the Step Value The value of the counter of the For. ..Next loop increases each time the loop repeats. But, that is not all it can do. We can change this by adding the 'Step' command to the end of the 'For' line of the loop. By doing this we can increase or decrease the value of the counter by anything we want.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/26/2010 for the course CNS 196 taught by Professor James during the Fall '10 term at Seneca.

Page1 / 8

Lab4 - Lab 4 INT213 This lab will concentrate on looping...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online