Problem with WHILE - WEND


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107

    Default Problem with WHILE - WEND

    I attached my program. Can someone tell me what is wrong with the highlited statement, and how can I accomplish the action?
    Attached Images Attached Images  
    Last edited by Russ Kincaid; - 26th May 2006 at 12:55.

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


    Did you find this post helpful? Yes | No

    Default

    Use IF THEN instead

    Code:
    IF (Footsw=1) OR (Ready=1) Then Start
    OR
    Code:
    While (FootSw=1) OR (Ready=1)
           LOW RENCA
           LOW EJECT
           WEND
    Last edited by mister_e; - 26th May 2006 at 12:57.
    Steve

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

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Wink

    First:
    Goto should not be used with "While" statement. Use "IF" instead.
    ex:
    Code:
    IF Footsw=1 or Ready=1 then Goto Start


    Second:
    Your statement should have been as below.
    Code:
    While Footsw=1 or Ready=1
    Goto start    'cant'be on the same line with While
    Wend
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    Thanks for the replies. I had tried IF - THEN but did not do that right either!

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


    Did you find this post helpful? Yes | No

    Default

    1. Parenthesis are important in most case
    2. I would never jump out of a WHILE statement using a GOTO. Using a flag or Validate the Conditions to get out of the WHILE/WEND loop is, IMHO, a better practice.

    Could be also..
    Code:
    Start:
        LOW RENCA
        LOW EJECT
        While (FootSw=1) OR (Ready=1) : WEND
    OR
    Code:
    Start:
        LOW RENCA
        LOW EJECT
        SpinHere: If (FootSw=1) OR (Ready=1) then SpinHere
    You may notice that one method generate less code space than the other.
    Last edited by mister_e; - 26th May 2006 at 13:10.
    Steve

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

  6. #6
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    Here is my problem: I tried the spinhere loop, it works but the following statements are a loop. I want the program to stay in the loop but as soon as either footsw or ready goes high, the program jumps back to the spinhere loop. I don't want it to do that. How do I do it?

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    SpinHere:
        LOW RENCA
        LOW Eject
        While (FootSw=0) OR (Ready=0)    
              '
              '    Do your loop here
              '
              wend
        goto Spinhere
    Steve

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

  8. #8
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    I have not explained my problem properly: I want a momentary switch closure (footsw) to cause the program to jump to a loop (freq. I don't want it to jump out of the loop when the switch opens.

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 14:46
  2. HSEROUT and Commas, What? Help Me Understand
    By altech6983 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 20th July 2009, 19:12
  3. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  4. while wend problem
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 19th March 2007, 02:53
  5. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59

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