Loop without first statement (C to visual main)

I have the following code in C:

for (i = 0; i < Nk; ++i)
    {
        // some actions using i as an index
    }
for (; (i < (Nb * (Nr + 1))); ++i)
    {
        // another actions. Here i starts from value in previous loop
    }

Now I'm trying to convert it to Visual Basic (really in VB 6.0 ...) The first part is simple:

For i = 0 To Nk - 1                                                             
    ' my actions
Next

But the second cycle confuses me a little. Is there a way to make this loop, or do I just need to add some kind of constant value here?

+4
source share
2 answers

I got a solution:

 For i = i To (Nb * (Nr + 1)) - 1
     ' my actions
 Next

Thanks @WhozCraig - it gives me the same solution.

+3
source

Just to have more options, another example might be:

dim lst = Enumerable.Range(0, (Nb * (Nr + 1)) - 1)

And then use LINQ expressions, for example (just composed):

lst.Select(function(x) 
             if x mod 2 = 0 then
                return x * 2
             else 
                return x
             end if
            end function) 
+1

Source: https://habr.com/ru/post/1670991/


All Articles