Shop OBEX P1 Docs P2 Docs Learn Events
Could some look at this FOR NEXT Routine and tell me if this the right way to d — Parallax Forums

Could some look at this FOR NEXT Routine and tell me if this the right way to d

sam_sam_samsam_sam_sam Posts: 2,286
edited 2008-03-10 04:55 in General Discussion
This seem to work the way that i want it to work but is this the right way to this

run:
DO··················
HIGH led·············
LOW chg··············
PAUSE dly1
··········
'charge·············
LOW led··············
HIGH chg
PAUSE dly1

'input
LOW led
INPUT chg
PAUSE dly2············
DEBUG CR, DEC ? chg

GOSUB Get_Time

·DEBUG HOME, HEX2 mins, ":", HEX2 secs, CR
·IF secs = $59 THEN
PAUSE 1000
·ENDIF

IF chg = 0 THEN········
· PAUSE dly3
ELSE
· IF chg = 1 THEN········ ······················· '·I want to run so many times to see if it still true if so then do something
· FOR idx = 1 TO 300···························· ·' This seem to work but is this the right way to do this
· DEBUG DEC5 ? idx , DEC5 ? leaps


From here down i want to run so many time if this statement stays true· IF leaps = 300 AND chg = 1 THEN EXIT·····
____________________________________________________________________________________________________
· HIGH led·············
LOW chg··············
PAUSE dly1
··········
'charge··············
LOW led··············
HIGH chg
PAUSE dly1

'input
LOW led
INPUT chg
PAUSE dly2············
DEBUG CR, DEC ? chg
leaps = leaps + 1

NEXT
·idx = idx + 1

ENDIF
· ENDIF
· IF leaps = 300 AND chg = 1 THEN EXIT·····
LOOP
_________________________________________________________________________________________________

DO
HIGH 14
PAUSE 100
LOW 14
PAUSE 100
LOOP

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

·
·
·
·
Sam

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-10 03:50
    This is too complicated for such a general question. Please simplify your posting or ask a more specific question.

    Without a very specific question, it's impossible to tell you if this is a better solution than some other.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-10 04:02
    mike

    thank you for your reply

    The rountine that i have here i only want to do something if the statement stay true for so long

    I want to run through this routine 300 time to see if it stays true

    IF leaps = 300 AND chg = 1 THEN EXIT



    ·DO··················
    HIGH led·············
    LOW chg··············

    PAUSE dly1

    ··········
    'charge·············
    LOW led··············
    HIGH chg
    PAUSE dly1

    'input
    LOW led
    INPUT chg
    PAUSE dly2············
    DEBUG CR, DEC ? chg

    · PAUSE dly3

    leaps = leaps + 1

    LOOP

    ··

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

    ·
    ·
    ·
    ·
    Sam
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-03-10 04:18
    Sam -

    Look at the PBASIC Help file for LOOP UNTIL.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Programming can't be all that difficult, it's nothing but 1's and 0's
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-10 04:47
    Bruce Bates

    Thanks for you reply

    ·This is what i try ed first was·LOOP UNTIL but as soon as· the statement was true it jump to the next stament which is not what i am wanting

    What i want is to loop so many time to see if it stay true then jump to the next statement

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

    ·
    ·
    ·
    ·
    Sam
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-10 04:55
    You can use the LOOP UNTIL statement, but you can also use the FOR / NEXT statement like:
    FOR i = 1 to 300
       ...
       IF NOT condition THEN EXIT ' This will cause the FOR / NEXT loop to quit early
       ...
    NEXT
    
Sign In or Register to comment.