Re: Loops that zero themselves? by Barry
Barry
Sun Aug 01 23:46:52 CDT 2004
On Sun, 1 Aug 2004 19:31:05 +0200, "Dave Neve"
<NoAdressForSpammers@Nofs.fr> wrote:
>Hi
>
>Yes, this bit I've got.
>
>But are you saying that running through a loop takes it back to its initial
>value.
Iterating through a loop does not reset the loop index. In fact the
loop index is normally incremented or decremented. Re-entering a loop
does reinitialize the index.
Your code has two loops, one for I and one for X. They are nested.
Thus the I loop cannot iterate until the X loop has iterated three
times. The first time through I, you enter X and iterate three times.
Then you iterate on I and enter X anew, thus iterating three times.
Then you iterate on I and do it all again. Finally, the I loop
terminates.
>
>If this was so, then loops like the ones below would run forever, going back
>to zero and running again.
>
>This is what I don't get about the code snippet.
>
>What put X back to 1????
As an example, assume you have a two dimensional array and you want to
step through each element. After you finish the first row, you want
to start at the beginning of the second row.
>
>Thanks in advance
>"Jezebel" <dwarves@heaven.com.kr> a écrit dans le message de news:
>uzTsPw7dEHA.3476@tk2msftngp13.phx.gbl...
>> You've got two loops here, on inside the other. For each value of I, you
>run
>> through the loop for X.
>>
>>
>> "Dave Neve" <NoAdressForSpammers@Nofs.fr> wrote in message
>> news:uLn8T25dEHA.592@TK2MSFTNGP11.phx.gbl...
>> > Hi
>> >
>> > The following code in a Visual Basic Net book
>> >
>> > Dim I As Integer , X As Integer
>> > For I = 1 to 3
>> > For X = 1 to 3
>> > Debug.Write("I = " & I & vbCrLf)
>> > Debug.Write("X = " & X & vbCrLf)
>> >
>> > produces
>> >
>> > I = 1
>> > X = 1
>> > I = 1
>> > X = 2
>> > I = 1
>> > X = 3
>> > I = 2
>> > X = 1
>> > I = 2
snip
<<Remove the del for email>>