Does a counter value get processed?


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322

    Default Does a counter value get processed?

    Hi All Again!
    So my next question is when you have a loop and you have a statement such as C = 0 to 6 the ICD will show the value of C and I noticed that C will have a value of 7, one higher than the limit of 6. Does your code actually process this value of 7 until it gets to the next C = 0 to 6? Seems like you would need a statement If C =< 7 go to .....?

    Thanks, Ed

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Does a counter value get processed?

    I suppose you're talking about a FOR-NEXT loop. From the manual:
    Code:
    FOR Count = Start TO End {STEP {-} Inc}{Body}NEXT {Count}
    1) The value of Start is assigned to the index variable, Count. Count can be a variable of any type.
    2) The Body is executed. The Body is optional and can be omitted (perhaps for a delay loop).
    3) The value of Inc is added to (or subtracted from if "-" is specified) Count. If no STEP clause is defined, Count is incremented by one.
    4) If Count has not passed End or overflowed the variable type, execution returns to Step 2.

    So your code FOR C = 0 to 6 will execute the body of the loop 7 times and then stop. C will be incremented to 7 but the body of the loop will not execute since 7 is larger than 6. That's where it stops.

    /Henrik.

Similar Threads

  1. counter
    By daydream in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd May 2012, 05:52
  2. IR Counter
    By partime in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 3rd June 2009, 13:34
  3. Counter
    By brenda in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th October 2008, 09:57
  4. Replies: 1
    Last Post: - 27th September 2007, 20:15
  5. Replies: 6
    Last Post: - 20th August 2006, 23:00

Members who have read this thread : 1

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