Gustav Brock
gustav at cactus.dk
Thu Aug 5 11:57:05 CDT 2004
Hi Brett >> I would have been silent. > Wow! I actually found something that would silence Gustav. Gotta make > a note of that... ;-) >> So, you would prefer the syntax: >> If I = 2 Then >> ' Do stuff >> End If I > Two points here: > First of all, that's not valid VB(A) syntax, so it's pretty hard to > truly comment on what I "prefer", since I couldn't have possibly used > that construct and formulated an opinion based on experience. Right??? Of course. I was moving along the tangent of Arthur's notes about "revised" syntax on the dba-tech list. > However, this is an easy one since your example is clearly not analogous > to what I stated. > A For...Next loop corresponds to a single loop variable. If statements, > Do...While loops, etc. are tied to conditions (I = 2, strLastName = > "Jones", etc.), not variables. If I place the letter I next to the End > If, it isn't very helpful since it is the condition (I = 2) that is the > basis of the code block. You are right about the Do .. Until loop. However, I find it very analogous to For I = 1 To 50 ' Do stuff Next I Also While .. Wend doesn't use it. Would you like: While N < 50 ' Do stuff Wend N > Repeating the entire condition string at the bottom of the block would > be far too wordy and the code maintainance required would outweigh its > benefit. Certainly. But I have thought about the Next (I) syntax. Though I seldom use nested loops and - when doing so - have found it very easy to keep track of the loops (I mean: one is indented inside another which is indented inside a third etc) I think that Next alone is more safe as it complete eliminates these classic typo errors: For I = 1 To 10 For J = 1 To 10 Next I Next J or: For I = 1 To 10 For J = 1 To 10 Next I Next I Using For I = 1 To 10 For J = 1 To 10 Next Next prevents and completely eliminates these errors. And I have yet to see a code example where this could confuse a decent programmer. To cut it out: How could the nested For/For/For .. Next/Next/Next loops ever cause an error? /gustav > OK, it's not Friday yet but I did read what you wrote: especially. >>> Makes a huge difference, especially when dealing with nested loops. > Had you written: >>> Makes a huge difference when dealing with nested loops. > I would have been silent. > So, you would prefer the syntax: > If I = 2 Then > ' Do stuff > End If I > Now, did I qualify for joining Arthur's "Club of Pendants"?? > /gustav >>> A huge difference - and added readability - for a single loop? >>> Is that you Brett? >> Um, take a moment to read my response before jumping all over it. I >> said: >>> Makes a huge difference, especially when dealing with nested loops. >> And yes, it does make a difference, even with a single loop. I don't >> have to scroll up a page of code to find the loop variable name, hence >> improved readability. >> But folks, Gustav is absolutely correct. It is not NECESSARY to >> specify the variable name in a Next statement. Nor is it NECESSARY to >> comment your code or use consistent naming conventions. Some of us >> just do these things for our own *special* reasons ;-) >> -----Original Message----- >> From: accessd-bounces at databaseadvisors.com >> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav >> Brock >> Sent: Thursday, August 05, 2004 8:48 AM >> To: Access Developers discussion and problem solving >> Subject: Re: [AccessD] Naming Conventions >> Hi Brett >>>>You don't need the last I; Next will do. >>> While you don't NEED the last I, many developers include it for >>> readability sake. Makes a huge difference, especially when dealing >>> with nested loops. >> A huge difference - and added readability - for a single loop? >> Is that you Brett? >> /gustav >> PS: >> --------------Please open with care!------------ This message will >> bypass some of your spam filtering rules. >>> -----Original Message----- >>> From: accessd-bounces at databaseadvisors.com >>> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav >>> Brock >>> Sent: Thursday, August 05, 2004 3:51 AM >>> To: Access Developers discussion and problem solving >>> Subject: Re: [AccessD] Naming Conventions >>> Hi Drew >>>> What's wrong with: >>>> For I=1 to 50 >>>> >>>> Next I >>> You don't need the last I; Next will do. >>> /gustav