Remove Text Formatting
Loading...

+ Reply to Thread
Results 1 to 12 of 12
  1. #1

    Default Nested "Select Case"s

    Are there any problems (besides being visually confusing) that one would encounter with nested "select case" routines, and if not, is there a limit to depth - i.e.- are 3 ok?

    Thanks

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,128

    Default Re: Nested "Select Case"s

    No problems that I know of, have done it many times though not that many levels (2-3).
    I don't know if there's a limit, can't think of why there would be.

    /Henrik.

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,216

    Default Re: Nested "Select Case"s

    The only limit I can think of is the "stack". But that's most likely the same stack we use for GOSUBs and nobody has complained about a limitation on that yet.

    "Total deduction on my part without a shred of supporting evidence"

    Robert
    Not as dumb as yesterday, but stupider than tomorrow!

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    849

    Default Re: Nested "Select Case"s

    A select case statement expands to a sequence of 'If This Then That' constructs when run through the compiler. Since there is no limitation using the If then, I do not anticipate a limit on the nesting of select case statements. Gosubs are in a different category wherein the compiler can decide to use the stack - or in some cases - to use gotos to acheive the same functionality and is totally compiler dependent.

  5. #5

    Default Re: Nested "Select Case"s

    Good to know, thanks!!

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,216

    Default Re: Nested "Select Case"s

    Quote Originally Posted by Jerson View Post
    ...Gosubs are in a different category wherein the compiler can decide to use the stack - or in some cases - to use gotos to acheive the same functionality and is totally compiler dependent.
    Ok, you got me on that one. How can GOTOs be used to achieve GOSUB logic?

    The going part is not a problem, but how does it come back without using a stack or some such memory to remember where it came from?

    Or does it replace the RETURN with a GOTO pointing to the statement following the GOSUB?

    Robert
    Not as dumb as yesterday, but stupider than tomorrow!

  7. #7
    Join Date
    Sep 2009
    Posts
    616

    Default Re: Nested "Select Case"s

    I dig many .LST files, and didn't see that compiler replaces GOSUB with GOTO.
    ON DEBUG uses GOTO after each PBP line, but before GOTO saves address to DEBUG_ADDRESS and, DEBUG_ADDRESSU variables. So you can use them to load program counter to get back from where PC jumped.

  8. #8
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    849

    Default Re: Nested "Select Case"s

    Not the Pic basic compiler we discuss here. I've seen other compilers which do. The compiler knows which piece of code goes where in code space in the same way that the compiler knows which variables are used by a subroutine(locals). Therefore, it can compute a goto and return via another goto. It is dependent on the compiler writer who decides how to implement. Think of code more in terms of ASM and you will be able to figure it out.

  9. #9
    Join Date
    Sep 2009
    Posts
    616

    Default Re: Nested "Select Case"s

    Ok, I was thinking just on PBP compiler. But return with goto would be possible if you call function/subroutine from one place only. And for that you actually don't need function or subroutine.

  10. #10
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    921

    Default Re: Nested "Select Case"s

    You could extend gosub nesting that way.
    Save program counter to variable, set it to the address
    of a routine, and rewrite the incremented value at the
    end of the routine.
    In the early days, with single code pages, it sounds like
    a reasonable way to extend the nesting a level.

  11. #11
    Join Date
    Sep 2009
    Posts
    616

    Default Re: Nested "Select Case"s

    If I remember correctly Darrel did that, it was 48 level software stack.
    EDIT:
    http://www.picbasic.co.uk/forum/showthread.php?t=151

  12. #12
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    921

    Default Re: Nested "Select Case"s

    Good idea lol The thought of actually writing another stack still hadnít cross my mind.

Similar Threads

  1. "select language" box at the top causes problems
    By Heckler in forum Forum Requests
    Replies: 2
    Last Post: - 22nd March 2016, 16:41
  2. Replies: 0
    Last Post: - 14th November 2013, 03:32
  3. Replies: 3
    Last Post: - 15th October 2012, 08:06
  4. Multiple "AND"'s in select case?
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st January 2010, 19:10
  5. "Select Case" Help
    By bmsherma in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th November 2009, 08:16

Members who have read this thread : 25

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts