So you're doing it wrong - same for overlapping for-next cycles![]()
So you're doing it wrong - same for overlapping for-next cycles![]()
If you mean my example, OK, it is a not efficient one but I was trying to show that you can have many Returns from the same sub.
Sure it can be made more compact or efficient, but still. Compiler has difficult time to check this for errors.
Ioannis
Ok, here is an example (not exact syntax, just to get idea)
In above example, if we remove RETURN, it will compile fine in PBP, but will produce unusable code. But even on ZX Spectrum, it would give us "Gosub without return" error, and save our time.Code:MAINCODE: 'do something high PORTC.0 PAUSE 500 low PORTC.0 Pause 500 GOSUB CHECKER GOTO MAINCODE CHECKER: TOGGLE PORTD.0 RETURN
Agreed. This is easy to check, but above we stated other cases that are difficult to check.
So a sub-without-return check in whole is not easy to implement. I suppose... Maybe Charles knows better to justify it.
Ioannis
There have been situations where if a test meets certain criteria you want to go through 5 sequences of code. However, if one of the criteria is missing, you want to skip the first sequence and do the other 4. On down the line, you may only need to do the last 2. The subroutine may look like;
Here is a legitimate case of needing only 1 RETURN for multiple subroutines.Code:Main: SELECT CASE Var CASE < 50 : GOSUB Sub1 CASE < 100 : GOSUB Sub2 CASE < 150 : GOSUB Sub3 CASE < 200 : GOSUB Sub4 CASE ELSE : GOSUB Sub5 END SELECT GOTO Main Sub5: TOGGLE LED1 Sub4: TOGGLE LED2 Sub3: TOGGLE LED3 Sub2: HIGH LATA.4 Sub1: LATB = 0 RETURN
That is exactly what I have on my mind in post #8.
Maybe it will be useful if compiler give just warning about missing RETUN.
But That wouldn't prevent bad stuff from happening same as it throwing an error wouldn't prevent that. So no real point of having it.
Another "bug" found - you can easily refer to out of array bounds and it won't give any error during compile
like
MAS var byte[5]
MAS[10]=20
Won't give any error or warning.
Bookmarks