Henning
2/23/2011 10:05:00 PM
"Helmut_Meukel" <Helmut_Meukel@bn-hof.invalid> skrev i meddelandet
news:ik3sqr$37m$1@news.eternal-september.org...
> Jeff Johnson legte dieses als Verknüpfung auf seinen Bildschirm :
>> "No Way" <tom@invalid.co.uk> wrote in message
>> news:ik396b$8fa$1@speranza.aioe.org...
>>
>>> Should there not be a "Next Y" on the line after wksOut.Cells and before
>>> End
>>> If ?
>>
>> Eww, you really do "Next <variable name>"? I guess it's a preference
>> thing,
>> but I just prefer the plain Next.
>>
>> For y = 1 To 10
>> For x = 1 To 20
>> ' blah blah blah
>> Next
>> Next
>>
>> It's not like you can force an outer loop to iterate by specifying its
>> variable "early," so I find naming the variable to be wordy. (Of course,
>> some
>> will argue that it makes the code self-documenting. I don't disagree, but
>> I
>> still don't find it in any way necessary.)
>
> Jeff, once upon a time ...
>
> IIRC, there were slight performance differences between "Next" and
> "Next i". But this depended on the basic version and changed.
>
> I once (in 2002) wrote a test programm to check if there is any
> difference between these 4 versions:
> For i = 1 To 255: ... :Next
> For i = 1 To 255: ... :Next i
> For i = 1 To 255 Step 1: ... :Next
> For i = 1 To 255 Step 1: ... :Next i
>
> The test itself is with 3 nested loops with 255 iterations each.
> The loop counters (i, j, k) dimmed as Byte, Integer, Long, Single and
> Double; 20 runs total.
>
> Guess what, no difference at all when the test app is compiled.
> Obviously the internal loop counter is not affected by the data type
> of the variable when the starting value is an integer and the step is 1.
> I had the app compiled 3 times: native code, native code favoring
> Pentium Pro, and P-Code.
> I just run the tests with those old compiled exes on my current PC
> (AMD Athlon, Win 7): no difference between both native code compilations,
> the P-Code is slightly (about 10%) slower.
>
> But I know, back in the old days, with VB3, VB-DOS, Basic PDS 7.1 and
> QuickBasic 4.5 there really were performance differences.
>
> Helmut.
>
>
The For/Next loop compiled is just:
at the start of the loop
jmp doit
loopit:
increment loop counter
doit:
.....
code inside loop
.....
cmp loopcounter, endvalue (compare loopcounter w endvalue)
ble loopit (jump if less or equal)
/Henning