Shop OBEX P1 Docs P2 Docs Learn Events
Can some one Help.........What is the different in these two code routine — Parallax Forums

Can some one Help.........What is the different in these two code routine

sam_sam_samsam_sam_sam Posts: 2,286
edited 2007-12-17 21:15 in BASIC Stamp
Hi, Everyone

I have a question what is the different about the way these two
codes work

I notice that they do not work the same
they seem·to say the same thing but one has ENDIF dose this a·make different in the
way it is compile·

Can some one explane what the different is·and when to use one over the other

Thanks to any one that can explane this to me

IF hrs = $00·AND mins = $05 AND secs = $00 THEN EXIT
LOW 15


················································· VS



IF hrs = $00·AND mins = $05 AND secs = $00 THEN
·EXIT
LOW 15
ENDIF

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·idea.gif·that you may have and all of your time finding them

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 12/17/2007 8:07:27 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-17 19:08
    Functionally, these should work the same. Probably the 2nd format gets translated into something like:
    IF NOT(hrs = $00 AND mins = $05 AND secs = $00) THEN GOTO skipIt
       EXIT
    skipIt:
    LOW 15
    
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-12-17 20:09
    EXIT can only be used inside a DO or FOR loop. Do you have a stripped down example of where the two forms give different results? I think they should be identical.

    This code:
    FOR mins=0 TO 9
    IF (hrs = $00 AND mins = $05 AND secs = $00) THEN EXIT
    LOW 15
    NEXT
     ' continue here on EXIT or NEXT fallthrough
    





    would translate to something like this in internal PBASIC:

    FOR mins=0 TO 9
    IF (hrs = $00 AND mins = $05 AND secs = $00) THEN GOTO label1
    GOTO label2
    label1: GOTO label3  ' this is the EXIT
    label2:  LOW 15
    NEXT
    label3:   ' continue here on EXIT or NEXT fallthrough
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Andy FoxAndy Fox Posts: 46
    edited 2007-12-17 20:14
    Actually, the difference is that the LOW 15 in the first code piece will *always* be executed, while the LOW 15 in the second code piece will only be executed when the IF...THEN statement is true.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2007-12-17 20:34
    Mike Green

    Functionally, these should work the same

    Thanks You for your reply

    I thought that should work the same

    I found out that they do not work same

    In this example·I am NOT RESETTING THE TIME TO $00 AND $00 for mins and secs

    I want to pick up where it left off when the power was LOSS so if the routine is done that stay done when the power come back on meaning that the LED should be OFF

    Here is an example

    IF secs > $05 THEN
    HIGH··LED
    ENDIF

    IF mins = $03 AND secs = $15 THEN
    EXIT
    LOW LED
    ENDIF

    The·LED would BLINK once and then be··OFF Which is what i want it to do

    If i could get this to where it would not BLINK at all it would be better but if not then i can live with this

    ·If you power OFF the basic Stamp power ON agian after the 3 mins and 15 secs had past


    IF secs > $05 THEN
    HIGH··LED
    ENDIF
    ·
    IF mins = $03 AND secs = $15 THEN EXIT
    LOW LED

    ·If you power OFF the basic Stamp power ON agian after the 3 mins and 15 secs had past

    Now with·this one when you power down the Basic Stamp
    The Led would STAY ON all the time This·is not what·is wanted in this case

    Now i would like understand why this seem to make a different·

    I have seen this before that it make a different where you put command next to THEN or on the next line and using ENDIF


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2007-12-17 21:02
    Tracy Allen
    Thank you for your reply here are both examples

    ·One works the way i want it to work the other

    One dose not

    ·I like to understand what is different


    Let me clear some thing UP these two routine work fine the way i want them to work they both turn the Led off As long you do not power down the Basic Stamp

    The Problem is when you·POWER the Basic Stamp DOWN after· 3 mins and 15 secs have past·and POWER It back UP is where the different thing are happing

    ·I would like to understand why they work different

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 12/17/2007 10:10:27 PM GMT
  • FranklinFranklin Posts: 4,747
    edited 2007-12-17 21:15
    As I understand the if statement, if you put the action at the end of the line the interpreter considers it a one line if. the next line is NOT part of the if.
    If you end the line with then the next lines are part of the if until you get to an endif.
    the first version does not require an endif while the second does.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
Sign In or Register to comment.