Use whatever fits you more, my friend
. I do use EXIT FOR, I follow your logic, I just was making a point: it is the same, both things do the same, the code looks the same.
Also, just for the sake of it, try to translate this to EXIT FORs:
Code:
FOR i% = 1 TO 31
FOR j% = 1 TO 31
FOR k% = 1 TO 31
IF (i% MOD 2) = 0 AND (j% MOD 3) = 0 AND (k% MOD 5) = 0 THEN GOTO outside
NEXT k%, j%, i%
outside:
I'll do it for you:
Code:
FOR i% = 1 TO 31
FOR j% = 1 TO 31
FOR k% = 1 TO 31
IF (k% MOD 5) = 0 THEN EXIT FOR
NEXT k%
IF (k% MOD 5) = 0 AND (j% MOD 3) = 0 THEN EXIT FOR
NEXT j%
IF (k% MOD 5) = 0 AND (j% MOD 3) = 0 AND (i% MOD 2) = 0 THEN EXIT FOR
NEXT i%
Now tell me what's more easily understandable. You need twice as code.
As I say, we both agree that we should tell newbies not to use GOTO when they can use better structures, for example to jump back or forth in the code, but you have to agree with me that GOTO has its uses and that using it intelligently when you have to doesn't make you a bad coder, but just the contrary.
I am talking about game loops where every cycle you save is vital.
A different case is, for example, using GOSUB. It is just deprecated, the introduction of SUBs with QB 2.0 and FUNCTIONS with QB 4.0 have made it completely useless. It is uglier and hard to read, so it's better to avoid it. Using GOSUB is just like use LET to define variables or CALL to call subroutines, but even worse. GOTO is also ugly and hard to read, but as still has its uses, I will still use it. And I can guarantee you that when you read my code you'll understand it completely.
Also note that I am talking about optimizing. I often use structured techniques in my programs but when I go for cycle hunting I change some stuff to its ugly (but faster) equivalent. For example, when you code a scripting engine for a game that has to read through a script file really often. You can't waste even a single extra comparison.
Note that this is not an endless rant, nor I want to stay "victorious" or something (It may look that way). I was just defining my scenario. There are different ways of coding different sorts of things. When you are teaching how to code someone, you better go with recursive algos, for example. When you apply them, you better turn them to iterative. They look ugly and sometimes almost unreadable (everyone should understand the recursive quicksort, but understanding the iterative one at first sight may be hard). Note that I was not critizising the claim "don't use GOTO" made to the newcomer. I was critizising the use of the sentence as a global truth, written on stone in the top of Everest. I think you all did an excellent work pointing this guy to the proper way of doing things, I don't want even a single shadow of doubt over that aspect.