IF Then Question


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: IF Then Question

    From the good ole manual
    IF..THEN can operate in 2 manners. In one form, the THEN in an IF..THEN is essentially a GOTO. If the condition is true, the program will GOTO the label after the THEN. If the condition evaluates to false, the program will continue at the next line after the IF..THEN. Another statement may not be placed after the THEN, it must be a label.

    If Pin0 = 0 Then pushd ' If button connected to Pin0 is pushed (0), jump to label pushd
    If B0 >= 40 Then old ' If the value in variable B0 is greater than or equal to 40, jump to old
    If PORTB.0 Then itson ' If PORTB, pin 0 is high (1), jump to itson
    If (B0 = 10) AND (B1 = 20) Then loop
    In the second form, IF..THEN can conditionally execute a group of Statements following the THEN. The Statements must be followed by an ELSE or ENDIF to complete the structure.

    If B0 <> 10 Then
    B0 = B0 + 1
    B1 = B1 - 1
    Endif

    If B0 = 20 Then
    led = 1
    Else
    led = 0
    Endif
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Jun 2005
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: IF Then Question

    Thanks Dave.

    The PBP3 manual itself left me confused as per the examples below;

    More Examples:
    IF B0 <> 10 THEN
    B0 = B0 + 1
    B1 = B1 - 1
    ENDIF
    IF B0 = 20 THEN
    led = 1
    ELSE
    led = 0
    ENDIF
    IF B0 >= 40 THEN old
    IF PORTB.0 THEN itson
    IF (B0 = 10) AND (B1 = 20) THEN mainloop
    IF B0 <> 10 THEN B0 = B0 + 1: B1 = B1 - 1

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: IF Then Question

    It is only a little bit out dated, but for the most part, IMHO, this is still the best manual.
    http://melabs.com/resources/pbpmanual/
    It is always open on a tab in my browser... for those special moments...
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Jun 2005
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: IF Then Question

    I agree Dave!

    Thanks.

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