Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   ASP (https://www.askmehelpdesk.com/forumdisplay.php?f=451)
-   -   Please Explain me the for loop of ASP (https://www.askmehelpdesk.com/showthread.php?t=643084)

  • Mar 12, 2012, 09:04 PM
    dendenny01
    Please Explain me the for loop of ASP
    <% @ language="VBScript" %>
    <% Option Explicit %>
    <html>
    <body>
    <%
    Dim I,j
    For I = 1 to 4
    For j = 1 to I
    Response.write I
    Next
    Response.write "<br>"
    Next
    </body>
    </html>

    Output:
    1
    22
    333
    4444

    Please explain me how this output is formed.
  • Mar 13, 2012, 12:22 AM
    indya
    The program here works on the concept of Nested Loops which means a loop within a loop.

    So, here loop 1 is For I = 1 to 4 within which is our loop 2 For j = 1 to i

    The loops will be executed as follows:

    1. i will be assigned the value 1 as loop one begins thus, i = 1
    2. j also will be assigned the value 1, j = 1
    3. Then we enter the Response.write i
      Next
      Response.write "<br>"
      Next
      where value of i will be written. Thus the out put is:
      1
    4. The execution goes back to check the inner loop, where the limit is j = 1 to i. Since i = 1, the inner loop ends and the first looping of the first loop ends too.
    5. Now, we execute the first loop again, as i = 2.
    6. Again the inner loop is executed, this time j = 1
    7. The value of i is printed as 2
    8. The execution goes back to inner loop again, to satisfy the condition j = 1 to 2, j takes the value 2, thus j = 2
    9. The inner loop is executed again, forming the output
      1
      22
    10. Same is followed of the values 3 and 4.


    In nested loop, if the outer looping is say of 10 times and the inner looping is 5, the total times the outer loop is executed will be 10 times, and the total times the inner loop is executed will 5X10 = 50 times.
  • Mar 13, 2012, 07:12 AM
    dendenny01
    Thanxx Indya you saved my day..
  • Mar 24, 2012, 10:19 PM
    dendenny01
    How can I transfer the Text value of form to radio button on submit or on click
  • Mar 25, 2012, 10:35 PM
    indya
    Not clear about what you are asking. I am assuming that you need to assign a user entered text value to a radio button.

    Just use the text property of the textbox and radiobutton to do so.

    radiobutton.text = textbox.text


  • All times are GMT -7. The time now is 11:56 AM.