Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 31st, 2009, 11:59 AM
Authorized User
Points: 241, Level: 4
Points: 241, Level: 4 Points: 241, Level: 4 Points: 241, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help in ASP for loop

I have a follwing for loop in my ASP page,

for i=0 to 10
' some code here
next

Now, if i = 2, I need to check for some conditon and if it is true then only I need to execute the code else I need to skip execution for i = 2 but need to check for i = 3 and so on...

for e.g.
for i = 0 to 10
if ( i = 2 and name = "test") then
' some code
else
continue
end if
next

How can we use the functionality of continue in ASP ?

I appreicate your help.
  #2 (permalink)  
Old August 31st, 2009, 12:23 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Cross site post...

Posted on 4guys as well

http://www.aspmessageboard.com/showt...237#post904237
__________________
Jason Hall

Follow me on Twitter @jhall2013
  #3 (permalink)  
Old August 31st, 2009, 12:35 PM
Authorized User
Points: 241, Level: 4
Points: 241, Level: 4 Points: 241, Level: 4 Points: 241, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but it is not that simple

for e.g.

for i = 0 to 10

if i <> 2 then
' some code
else
if ( name = 'test' ) then
' same code as above
else
i = i + 1
end if
end if

next

I am trying to do something like as above but it is not working. Can you please guide me how can I do that ?
  #4 (permalink)  
Old August 31st, 2009, 12:49 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Hmm...

Do you want to run the code only if i=2 AND name=test
or do you want to run it if i=2 OR name=test?
__________________
Jason Hall

Follow me on Twitter @jhall2013
  #5 (permalink)  
Old August 31st, 2009, 01:14 PM
Authorized User
Points: 241, Level: 4
Points: 241, Level: 4 Points: 241, Level: 4 Points: 241, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I want to run the code for i = 0, 1, 3 to 10 and i = 2.

but for i =2 I need to check some other condition too....if it is true then only i need to run the code or else just skip it and go to i = 3

so it is basically for i = 2 AND name = 'test'
  #6 (permalink)  
Old August 31st, 2009, 01:17 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default OK...

Code:
for i=0 to 10
  if i<>2 then
    'Process code
  else
    if name="test" then
      'Process code
    end if
  end if
next
__________________
Jason Hall

Follow me on Twitter @jhall2013
  #7 (permalink)  
Old August 31st, 2009, 02:18 PM
Authorized User
Points: 241, Level: 4
Points: 241, Level: 4 Points: 241, Level: 4 Points: 241, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks so much for your help but I tried the exact same thing but somehow it is not processing code for i = 3 and i = 4.
  #8 (permalink)  
Old August 31st, 2009, 04:13 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

No you showed this code before:
Code:
for i = 0 to 10
       if i <> 2 then
             ' some code
       else
             if ( name = 'test' ) then
                   ' same code as above
             else
                    i = i + 1
              end if
       end if
next
which is not the same as:
Code:
for i=0 to 10
  if i<>2 then
    'Process code
  else
    if name="test" then
      'Process code
    end if
  end if
next
Notice i don't have the i = i + 1 which means you would be effectively skipping numbers in the loop...
__________________
Jason Hall

Follow me on Twitter @jhall2013
  #9 (permalink)  
Old September 1st, 2009, 03:11 PM
Authorized User
Points: 241, Level: 4
Points: 241, Level: 4 Points: 241, Level: 4 Points: 241, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks so much for your help and I solved the issue....
  #10 (permalink)  
Old September 1st, 2009, 03:12 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

Glad to hear it... what did you do?
__________________
Jason Hall

Follow me on Twitter @jhall2013




Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP dynamic SQL query with for loop? hman Classic ASP Databases 3 December 13th, 2006 08:56 PM
How to interrupt processing the LOOP in ASP.NET Dmitriy ASP.NET 2.0 Professional 2 November 29th, 2006 12:19 PM
How to interrupt processing the LOOP in ASP.NET Dmitriy General .NET 2 January 13th, 2006 08:43 AM
How to interrupt processing the LOOP in ASP.NET Dmitriy ASP.NET 1.0 and 1.1 Professional 2 December 15th, 2005 04:16 PM
How to interrupt processing the LOOP in ASP.NET Dmitriy Classic ASP Professional 0 December 13th, 2005 08:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.