0

So I'm new to VB.Net and still a bit grumpy working without a semicolon but that's fine. I'm working my way around. Any advice is appreciated !

I got this function:

    friend sub find_in_Array(byval string1 as string, byval string_args* as string)

          try

             Dim x_index_count as integer = 10000
             Dim z_index_count as integer = 10000
             Dim array(x_index_count, z_index_count) As String

             for x = o to x_index_count -1

                 dim my_data(y_index_count) as string

                 if not string.isnullorempty(string1) then
                     if not array(x,y).contains(string1) then GoTo LineNext
                 end if

                 ''// Now Following another 10 checks for additional args* given

                 ListfromClass.Add(my_data)

         LineNext:
                 next

         catch ex as exception

            setSmThnToLogFile(ex.Message)

        end try

    end sub

The Two-Dimensional Array Axis X and Z are rounded but no overestimated. And they're generally the reason why I'm asking this question.

Looping through arrays is not the time I want my code to spend with. Every chance to reduce it is fine with me.

unfortunately Visual Basic doesn't accept this code version :

friend sub find_in_Array(byval string1 as string)
      try
         Dim x_index_count as integer = 10000
         Dim z_index_count as integer = 10000
         Dim array(x_index_count, z_index_count) As String

         for x = o to x_index_count -1
             dim my_data(y_index_count) as string

             if not string.isnullorempty(string1) then
                 if not array(x,y).contains(string1) then Next
             end if
         next
     catch ex as exception
        setSmThnToLogFile(ex.Message)
    end try
end sub

Because Next can't reach out of the if-condition-block to the for-loop-block.

But I still want to do it.

There's one big argument for this case. To ignore everything because the time difference on recent released pcs might not even be noticeable. (Around 1 Second). But I'm ignoring this one because

as it is, it just doesnt make sense to process code I don't need it to.

If there's an alternative for the second version of code not involving a GoTo Line ( that's not nearly as much of a devil as many say but still a saying ) I'd be glad to hear.

Thanks in Advance !

Jonas
  • 121,568
  • 97
  • 310
  • 388
Maxwell
  • 1
  • 1

2 Answers2

0

Continue For

How to: Skip to the Next Iteration of a Loop (Visual Basic) 1

andyb
  • 770
  • 5
  • 11
0

It's not clear exactly where you want your program flow to go to in this case, but a choice of either:

Exit For 'Transfers control out of the For Each loop.

Continue For 'Transfers control to the start of the For Each loop.the next one

You can find the documentation on these here: https://msdn.microsoft.com/en-us/library/5ebk1751.aspx

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143