Information générale
Catégorie:
Codage, syntaxe et commandes
Nadya --
>> The general guideline I use is this:
>>
>>1. If the loop is based on a specific number of operations, I use FOR..NEXT.
>>
>Jay, this loop uses a counter, that's why I used for next loop. All loops should be terminated, if user decides to esc, so I had to put exit in each inner loop, which uses for next construct. I asked this question here while ago and this was the advice I got, so I scaned through the code and did it.
As you say, you can do the same processing using a DO WHILE and a FOR..NEXT with an EXIT. In a sense, it's a different style but the same substance.
Your example addresses exception handling, rather than regular processing, so I think you could make a good argument either way.
But, as I use these guidelines, they're part of a larger approach to programming.
I find that logical values are very useful in a variety of ways:
1. They only have 2 values, so they're easy to master!
2. They help me think through the actual process that I'm programming.
3. When I use them, move the program towards self-documentation.
Now, regarding the particular instance of FOR..NEXT/DO WHILE.
A DO WHILE puts all conditions in the condition clause -- so it's clear what issues are being tested for. By looking at one line, I get a feel for what the whole routine does. On the other hand, in a FOR..NEXT situation with a variety of EXITS, I have to look through the entire routine to make sure that grasp what it's doing.
I think it makes a more readable program -- but, that's IMHO%).
>>2. If the loop is based on a specific condition, I use DO WHILE.
>>
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement