ASP jumps out of the loop to avoid traps

Source: Internet
Author: User

You must jump out of the nested for loop in time. Otherwise, you may encounter an inexplicable problem, just as I did at the beginning:

Write an online color purchase program. After you select the value of the check box on the Color purchase page, the program generates and outputs the possible number of notes based on these values.
For each B in Iddi
For each C in iddii
For each d in iddiii
For each E in iddiv
For each F in iddv
For each G in iddvi
For each h in iddvii

'If B = "" then
'Response. Write ("the number of data digits is incomplete. Please reselect ")
'Response. End ()
'End if
If caizhong = "3D" or caizhong = "3" then
N = trim (B) & trim (c) & trim (d)
STR = STR & N & "& nbsp ;"
Elseif caizhong = "arrange 5" then
N = trim (B) & trim (c) & trim (d) & trim (e) & trim (f)
STR = STR & N & "& nbsp ;"
Elseif caizhong = "" then
N = trim (B) & trim (c) & trim (d) & trim (e) & trim (f) & trim (g) & trim (h)
STR = STR & N & "& nbsp ;"
End if
Next
Next
Next
Next
Next
Next
Next

The output is

<% = STR %>
It is strange that the output is normal only when caizhong = "", and the STR value is empty in other cases. Who knows what's going on? Help me. Thank you.

I tried to explain it everywhere. I was about to hit the wall when I was depressed. Finally, when I checked the for loop, I saw the statement exit for jumping out of the loop. I thought, is there no reason to jump out of the loop? Modify the program to the following code:
For each B in Iddi
For each C in iddii
For each d in iddiii
If caizhong = "3D" or caizhong = "3" then
N = trim (B) & trim (c) & trim (d)
STR = STR & N & "& nbsp ;"
Exit
End if
For each E in iddiv
For each F in iddv
If caizhong = "arrange 5" then
N = trim (B) & trim (c) & trim (d) & trim (e) & trim (f)
STR = STR & N & "& nbsp ;"
Exit
End if
For each G in iddvi
For each h in iddvii
If caizhong = "" then
N = trim (B) & trim (c) & trim (d) & trim (e) & trim (f) & trim (g) & trim (h)
STR = STR & N & "& nbsp ;"
End if

Next
Next
Next
Next
Next
Next
Next

Save and run. Haha, I am so excited that I have finally shown what I mean.
You should be careful when using for loop nesting later.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.