3 ms·
Ah, the OP probably has better ideas, but I know what I like! E.g.: Do Forever If A Then Leave If B Then Call X If C Then Iterate
by graycat 9y ago
Ah, the OP probably has better
ideas, but I know what I like!
E.g.:
Do Forever
If A Then Leave
If B Then Call X
If C Then Iterate
Call Y
Leave
End
Ah, that style of loop
writing may cause some
purists to scream bloody
murder!
- mcguire 9y agoI used to know a guy who used a loop structure something like that. For every loop. One of threw weirdest things I have ever seen. Some people seem determined to cause facial tics in everyone they meet.
- graycat 9y ago> Some people seem determined to cause facial tics in everyone they meet. Maybe so, but not me. So, what is the justification for the Do Forever loop above? First, I illustrate that we can want to exit the loop for (A) whatever conditions are discovered in the loop and (B) at any point in the loop and not just the beginning or end which is the usual situation, e.g., for Do i = 1, 10 or Do While X If I write Do I = 1, n does the loop logic deciding when to exit ever form n + 1? If n is the largest integer, then maybe we'd like to know. With Do Forever we may have more control, enough more to avoid forming n + 1 unless we really want to. Second, when I start writing a loop, I may not have yet worked out all the details or how to get what I do want just from some Do While X Etc. So, I just start the loop with Do Forever and work out the exit conditions as I keep typing. Third, with Do Forever can often get the results of using a GOTO without actually doing so. So, if the target of the GOTO would be just after the loop End, then can get there within the loop with just a Leave. Of course, when write such a loop with Do Forever, should write some comments that explain (A) what the purpose of the loop is and (B) how the code in the loop does accomplish that purpose. That is, should not force someone reading the code to guess at (A) and confirm (B). For proofs of correctness based on the usual mathematical induction, I'm not convinced that loops with Do Forever are fundamentally more difficult. > Some people seem determined to cause facial tics in everyone they meet. Maybe so, but not me.