For Next statement

  • Thread starter Thread starter Norton
  • Start date Start date
N

Norton

May i know if there is any method that can perform a skip within a loop?
Like this


For i = 1 to 100
if i = 5 then MOVENEXT '<--No this method
if i = 10 then exit for
Next


Thx a lot !
 
Norton,
\\\
For i = 1 to 100
if i <> 5 then
if i = 10 then exit for
)
end if
Next
///
or
\\\
For i = 1 to 100
select case i
case 5
case else
if i = 10 then exit for
end select
Next
///
What is wrong with those normal instructions for that?

Cor
 
i have many cases to handle, so trying to find a way to simplify the code

just like if and iif :-p
 
i have many cases to handle, so trying to find a way to simplify the code

Therefore I showed that sample with the select case too

Have a look for it

Cor
 
* "Norton said:
May i know if there is any method that can perform a skip within a loop?

In addition to Cor's reply: In VB.NET Whidbey (2005) there will be a
'Continue' keyword...
 
Norton,
I would seriously consider if a for loop is the appropriate construct to
use, as you are skipping 5 & most other numbers (such as 11 to 100). If it
is I would use a Select Case similar to what Cor showed:
For i = 1 to 100
Select Case i
Case 5
'<--No this method
Case 10
Exit For
Case 11
' Of course we never get here! ;-)
Case 2,4,6,8
' do something else special
Case Is = i Mod 4
' do something really special & confusing ;-)
Case Else
' non special cases
End Select

Note I moved the 10 case to be part of the select case itself, rather then
the else. Sometimes having it part of the else as Cor showed is beneficial.
It really depends on what you are doing...

Hope this helps
Jay
 
Back
Top