Does anyone know if there are any limitations to nesting "if" commands eg
if b0=1 then
if b2=1 then
if b3=1 then
endif
endif
endif
Gosubs can be nested 4 deep and any more than that and the program will give no error message or warning and just start going haywire. I'm wondering if there are any similar limitations to the "if" command?
Thinking about answering my own question and having written compilers in the past I think all if/then/else commands can be broken down to goto statements at compile time eg
if a condition is false then goto (either else or endif)
continue code if it was true
goto endif
else - location for goto from above
continue code
endif
continue code
So no stacks are needed and so nesting should not be a problem. Is this correct?
Also another question - how does the picaxe compiler handle this example of bad programming:
main:gosub mysubroutine
goto main
mysubroutine:
code
goto main
code
return
When mysubroutine is called this will put the return location onto the stack, but if there is a jump out of the subroutine the return won't get called. This is a simple example -the goto could have jumped to another location then a goto to a third location then a goto main. Does the stack then overflow and the program start behaving strangely in the same way that nesting too many gosubs causes strange behaviour?
Help would be most appreciated!
if b0=1 then
if b2=1 then
if b3=1 then
endif
endif
endif
Gosubs can be nested 4 deep and any more than that and the program will give no error message or warning and just start going haywire. I'm wondering if there are any similar limitations to the "if" command?
Thinking about answering my own question and having written compilers in the past I think all if/then/else commands can be broken down to goto statements at compile time eg
if a condition is false then goto (either else or endif)
continue code if it was true
goto endif
else - location for goto from above
continue code
endif
continue code
So no stacks are needed and so nesting should not be a problem. Is this correct?
Also another question - how does the picaxe compiler handle this example of bad programming:
main:gosub mysubroutine
goto main
mysubroutine:
code
goto main
code
return
When mysubroutine is called this will put the return location onto the stack, but if there is a jump out of the subroutine the return won't get called. This is a simple example -the goto could have jumped to another location then a goto to a third location then a goto main. Does the stack then overflow and the program start behaving strangely in the same way that nesting too many gosubs causes strange behaviour?
Help would be most appreciated!