ELSEIF Block Would be Good.


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    As far as I know it already does. (just not all in one word)
    Code:
    IF Condition then
        Something
    else 
        if Condition2 then
            something else
        endif
    endif
    _
    DT

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    And in some forms, literally KILLS free flash space...

  3. #3
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    That's not the same. True ELSEIF structure will exit out of the nest as soon as it hits the first true condition. Same as Select Case.

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    But PBP doesn't have the virtually (pun intended) unlimited stack space like Windows does.
    Gotta draw the line somewhere I suppose.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    And in some forms, literally KILLS free flash space...
    No difference, no additional code space.

    Quote Originally Posted by T.Jackson View Post
    That's not the same. True ELSEIF structure will exit out of the nest as soon as it hits the first true condition. Same as Select Case.
    No difference. That's what it does.

    Added: No additional Stack space either.

    _
    Last edited by Darrel Taylor; - 9th May 2007 at 09:39. Reason: Stack
    DT

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    What I'm saying is that multiple IF/THEN statements:
    IF this then
    that
    ENDIF
    IF this then
    that
    ENDIF

    made back-to-back-to-back, takes more flash space than successive IF/THEN statements:
    If this then
    if this then
    if this then
    that
    endif
    endif
    EndIf

    I had to use the successive version of the IF/THEN vs. the back-to-back version in my MP3 player in a number of places (no way around it due to how the program was set up, either it was bad style or I just had too much going on to keep tabs on, just the nature of the program's complexity). Anywhos...when I changed everything over to the successive type, I saved a load of code space. I never did check in to why I saved as much space as I did, it just did, and I'm happy.

    As far as stack space goes, are you saying that there aren't any calls involved with doing an if/then?

  7. #7
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    As far as I know it already does. (just not all in one word)
    Code:
    IF Condition then
        Something
    else 
        if Condition2 then
            something else
        endif
    endif
    It's not the same if a multitude of ELSEIF is required ...

    Code:
    IF Condition then
        Something
    else 
        if Condition2 then 'ELSEIF 1
            something else
        endif
    
       '// Even if ELSEIF 1 is true then we still validate this argument  
       if Condition2 then 'ELSEIF 2
            something else
        endif
    
       '// Likewise, even if ELSEIF 2 is true then we still validate this argument  
        if Condition3 then 'ELSEIF 3
            something else
        endif
    endif
    I guess you could have a GOTO in each block to exit out of the nest - but as I said before, true ELSEIF would make a nice addition to PBP.
    <hr/>

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    It'll work. You just need to add the next condition in the last one's ELSE clause.
    Code:
    IF Condition then
        Something
    else 
        if Condition2 then
            something else
        else
            if Condition3 then
                even more
            else
                if Condition4 then
                   4's good
                else
                    this is the final ELSE, if none of the others match
                    it ends up here
                endif
            endif
        endif
    endif
    Quote Originally Posted by skimask
    As far as stack space goes, are you saying that there aren't any calls involved with doing an if/then?
    Correct. If/Thens don't use the stack. They use GOTO's only.

    Added: There is no limit to the "Nested" levels of IF/THEN's.
    _
    Last edited by Darrel Taylor; - 9th May 2007 at 18:25. Reason: Nested Levels
    DT

  9. #9
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    O.K. I agree that to be logically equivalent to ELSEIF. But there's one downside, how do you plan on indenting 20 or more nested arguments?
    But, you have clearly illustrated just how easy it would be for MELABS to implement support for ELSEIF. PBP already has the raws required.
    Last edited by T.Jackson; - 10th May 2007 at 03:38.

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    no problem, i use a dual screen video card and two monitor
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by T.Jackson
    how do you plan on indenting 20 or more nested arguments?
    That's just the way I format things.
    You dont have to do it that way.

    Here's one that skimask will like. (lottsa colons)
    Code:
    IF Condition  then
        Something
    else:IF Condition2  then 
        something else
    else:if Condition3  then
        even more
    else:if Condition4  then
        4's good
    else
        this is the final ELSE, if none of the others match
        it ends up here
    endif:endif:endif:endif
    DT

  12. #12
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    You're missing the point. While I agree that what you're saying will indeed do the same job (regardless of how you format it) there's still more effort from the programmer that's required. There's additional thought process along with extra typing. And, I have a sneaking suspicion that traditional ELSEIF structures might be somewhat better optimized.

Similar Threads

  1. config bits
    By brianD in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th February 2010, 13:45
  2. Setting up internal clock correctly?
    By JohnM in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th March 2008, 20:29
  3. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  4. Bootloader and Instant Interrupts Atn:_DT_
    By Josuetas in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 16th May 2007, 01:59
  5. PortE problems (PIC18F4455)
    By RubenR in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 12th July 2006, 15:26

Members who have read this thread : 0

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