Then 80% of my programs wouldn't compile. I often use multiple entry point in same sub. And have only one return at end.
Then 80% of my programs wouldn't compile. I often use multiple entry point in same sub. And have only one return at end.
Or the reverse. Have one entry and multiple exits:
IoannisCode:gosub test .... test: if x=1 then a=1 return endif if x=2 then a=2 return endif return
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
Bookmarks