Cor said:
You will always see simple errors in quick made code.
It thought it did work however that is strange, it has to be
\\\
Private Sub Whatever
Dim myarray() As String = {"1", "2", "3", "4"}
myproc(myarray, "First")
myproc(myarray, "Second")
End Sub
Private Sub myproc(ByVal myarray() As String, _
ByVal fase As String)
Static i As Integer
Dim y As Integer
For i = i To myarray.Length
If y = 2 Then Exit For
y += 1
Console.Write(i.ToString & " " & fase & vbCrLf)
Next
End Sub
///
What are you trying to do in this routine? The second call to myproc i
will be myarray.Length so the loop fails. The static keyword keeps the
value of 'i'. Though take a step back and look at the code you wrote.
No-one will use this kind of code in production software, because there
are far better ways to accomplish the same thing, which ARE more
readable as you can determine what a variable's contents is when the
routine is started (i.e. deterministic code, vs. your non-deterministic
code).
You could mimic an iterator using a wrapper class, and which calls a
delegate on each iteration (to make it generic). Though to set this up
is not transparent, i.e.: it requires work, something which is
transparent for the user of a .NET 2.0 iterator: just iterate over the
structure, whatever the structure represents.
Iterators are just to make foreach loops possible. So you can for
example foreach over a linked list, now that's a bit problematic, (not
undoable). Though there is always a way to do it differently, for
example by using the structures characteristics, in my example of the
linked list, you could use a While Not node.Next Is Nothing (C#:
while(node.Next!=null) {} ). That won't change in .NET 2.0. With
iterators, you just can create another way to iterate over a structure,
one which is usable in foreach. So if you step away from 'I want to use
foreach' and look at the code and just implement what gets the job
done, you will see iterators aren't a requirement, but a convenience
(and a convenience to the user if I'd might add

)
FB
--