-
Oct 30th, 2010, 08:44 AM
#1
Thread Starter
Hyperactive Member
What's the difference btw Next i and Next?
Hi guys, i'm quite confused with the difference between Next i and Next in the loop sequence?
I have try to stimulate the both cases above and it's seem that they are the same and why some of the developers using different method? Is that anyone of it preferable that the other one?
Please advise....
I'm still on the path of learning....
-
Oct 30th, 2010, 08:46 AM
#2
Re: What's the difference btw Next i and Next?
In terms of behaviour and speed they are identical.
The difference is in how readable the code is - if you specify the variable then it is easier to match it up to the relevant For line, which becomes more important as the code gets larger and/or more complex.
-
Oct 30th, 2010, 09:07 AM
#3
Thread Starter
Hyperactive Member
Re: What's the difference btw Next i and Next?
Hi si_the_geek, thanks for the explanation....However, i prefer to use Next.... =)
I'm still on the path of learning....
-
Oct 30th, 2010, 09:24 AM
#4
Hyperactive Member
Re: What's the difference btw Next i and Next?
Consider the following code.
Code:
For outer = 0 to 10
For inner = 0 to 10
' ....
Next outer
Next inner
The error is obvious as the loops are mismatched. Now look at this.
Code:
For outer = 0 to 10
For inner = 0 to 10
' ....
Next
Next
The error is hard to find even though I deliberately put it there because in fact there is no error. The compiler has incorrectly assumed I knew what I was doing because I gave it less information than I could have. What may save a small amount of typing may end up costing a lot more in time if you are not very careful.
Slower than a crippled Vista
More buggy than a fresh XP install
Look! Down the road, some 50 miles behind the drunken snail.
It's Ubuntu!
-
Oct 31st, 2010, 05:08 AM
#5
Junior Member
Re: What's the difference btw Next i and Next?
I is an identifier, nothing more.
By explicitly stating what you're doing it becomes a lot easier to read.
The example above is a good.
You can also have code before and after embedded loops. By stating which one you're ending you make sure that you don't break away from the wrong one.
You may want to use next if (for some reason) you make a class in the opening For. Other than that I can't think of a good reason for not stating it.
-
Oct 31st, 2010, 07:36 AM
#6
Re: What's the difference btw Next i and Next?
If the For/Next statements are properly indented, it is easy to spot which Next goes with which For.
Using an identifier is only necessary when poor indentation practices are in play.
-
Oct 31st, 2010, 07:50 AM
#7
Junior Member
Re: What's the difference btw Next i and Next?
If you need to document your code listing it helps a lot, especially where proper tabbing my not be possible.
Agreed it isn't necessary, but there's no good reason not to.
Experience with .Net:
Open:"Ooo, this is pretty"
Few minutes later:"Wow lots of useful Controls"
After an hour or so:"Hmm... seem to be doing very little programming here"
Some time later:"WHAT HAVE THEY DONE WITH MY CONTROL ARRAYS?!?!?!"
vb6:Ahh...
-
Oct 31st, 2010, 08:26 AM
#8
Re: What's the difference btw Next i and Next?
I consider repeating the variable after a Next keyword to be a vestigial feature and almost never use it. I'm not sure it makes a huge difference in performance one way or the other, though it can help the compiler find errors in your loop nesting.
It is a syntax error to do it in VBScript however, so I avoid using the archaic syntax in VB6/VBA as well.
-
Nov 1st, 2010, 12:51 AM
#9
Re: What's the difference btw Next i and Next?
I never specify the variable in the Next statement.
To be honest, I have no idea what posters are talking about with regard to errors. Next always returns to the previous For. All Next statements are identical. In other words, mixing up the order of the Nexts is not conceptually possible.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|