Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default short circuit for next; continue?

Is there a way to do this in vba? (I can do this with structure but I
want to know if there is a perl/C# analog to (continue")

for x = 2 to y

answer = sub_testing()
if answer = 1
continue ' skip the reset of loop code and go back and get the
next value. No point in going on
end if

do more stuff
do more stuff

next

thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default short circuit for next; continue?

Not sure I understand what you mean, but I think maybe Exit For is what you
are looking for.
For i = 1 To 10
If condition is met then
Exit For
End If
'Do stuff
Next
The Exit for will take you out of the loop to the next line of code.


"cate" wrote in message
...
Is there a way to do this in vba? (I can do this with structure but I
want to know if there is a perl/C# analog to (continue")

for x = 2 to y

answer = sub_testing()
if answer = 1
continue ' skip the reset of loop code and go back and get the
next value. No point in going on
end if

do more stuff
do more stuff

next

thank you.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default short circuit for next; continue?

On Jan 31, 9:10*am, "JLGWhiz" wrote:
Not sure I understand what you mean, but I think maybe Exit For is what you
are looking for.
For i = 1 To 10
* If condition is met then
* * *Exit For
* End If
* 'Do stuff
Next
The Exit for will take you out of the loop to the next line of code.

"cate" wrote in message

...

Is there a way to do this in vba? *(I can do this with structure but I
want to know if there is a perl/C# analog to (continue")


for x = 2 to y


*answer = sub_testing()
*if answer = 1
* *continue *' skip the reset of loop code and go back and get the
next value. *No point in going on
*end if


*do more stuff
*do more stuff


next


thank you.


With if's it would look like this

For i = 1 To 10
If condition is met then
do stuff
end if
Next

verses (with continue) The same result

For i = 1 To 10
If condition is NOT met then
continue
end if
do stuff
Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default short circuit for next; continue?

There's not a direct equivalent to 'continue' in VB but two ways to achieve
same with your example

for x = 2 to y

answer = sub_testing()
if answer < 1 then

do more stuff
do more stuff

end if

next


for x = 2 to y

answer = sub_testing()
if answer = 1
goto continue
end if

do more stuff
do more stuff

continue:
next

("continue" here is just a label named whatever you want)

I should add purists don't like use of Goto and will give all sorts of
(good) reasons not to use it. That said if used sparingly it can be useful.

Regards,
Peter T


"cate" wrote in message
...
Is there a way to do this in vba? (I can do this with structure but I
want to know if there is a perl/C# analog to (continue")

for x = 2 to y

answer = sub_testing()
if answer = 1
continue ' skip the reset of loop code and go back and get the
next value. No point in going on
end if

do more stuff
do more stuff

next

thank you.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default short circuit for next; continue?

On Jan 31, 9:19*am, "Peter T" <peter_t@discussions wrote:
There's not a direct equivalent to 'continue' in VB but two ways to achieve
same with your example

for x = 2 to y

* answer = sub_testing()
* if answer < 1 then

* do more stuff
* do more stuff

* end if

next

for x = 2 to y

* answer = sub_testing()
* if answer = 1
* * * *goto continue
* end if

* do more stuff
* do more stuff

continue:
next

("continue" here is just a label named whatever you want)

I should add purists don't like use of Goto and will give all sorts of
(good) reasons not to use it. That said if used sparingly it can be useful.

Regards,
Peter T

"cate" wrote in message

...

Is there a way to do this in vba? *(I can do this with structure but I
want to know if there is a perl/C# analog to (continue")


for x = 2 to y


*answer = sub_testing()
*if answer = 1
* *continue *' skip the reset of loop code and go back and get the
next value. *No point in going on
*end if


*do more stuff
*do more stuff


next


thank you.


Thank you.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default short circuit for next; continue?

If I understand

y=12
for i = 2 to y
if lcase(cells(i,"b"))="yes" then
msgbox cells(i,"c")
exit for
else
msgbox "go on"
end if
next i

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"cate" wrote in message
...
Is there a way to do this in vba? (I can do this with structure but I
want to know if there is a perl/C# analog to (continue")

for x = 2 to y

answer = sub_testing()
if answer = 1
continue ' skip the reset of loop code and go back and get the
next value. No point in going on
end if

do more stuff
do more stuff

next

thank you.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default short circuit for next; continue?

Just change your If..Then test to the negative and include you "do more
stuff" inside the If..Then block, that way, the x=1 condition will naturally
"fall through"...

For x = 2 To y
answer = sub_testing()
If answer < 1 Then
do more stuff
do more stuff
End If
Next

--
Rick (MVP - Excel)


"cate" wrote in message
...
Is there a way to do this in vba? (I can do this with structure but I
want to know if there is a perl/C# analog to (continue")

for x = 2 to y

answer = sub_testing()
if answer = 1
continue ' skip the reset of loop code and go back and get the
next value. No point in going on
end if

do more stuff
do more stuff

next

thank you.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Continue equation mparker Excel Discussion (Misc queries) 1 May 11th 09 12:50 PM
VBA continue kramer31 Excel Programming 21 November 1st 06 04:36 AM
to continue down in the same row alex178 Excel Discussion (Misc queries) 2 July 8th 06 05:34 PM
Continue Steph[_6_] Excel Programming 0 January 31st 06 05:50 PM
Find a value if there continue Tempy Excel Programming 2 May 19th 04 08:53 PM


All times are GMT +1. The time now is 06:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"