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

Info icon This 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
Image of page 1

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

View Full Document Right 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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern