Regarding WHILE...WEND


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2008
    Posts
    19

    Default Regarding WHILE...WEND

    The manual states

    5.85. WHILE..WEND
    WHILE Condition
    Statement...
    WEND
    Repeatedly execute Statements WHILE Condition is true. When the
    Condition is no longer true, execution continues at the statement
    following the WEND. Condition may be any comparison expression.
    i = 1
    WHILE i <= 10
    Serout 0,N2400,[”No:”,#i,13,10]
    i = i + 1
    WEND
    What if this happens:

    Code:
    WHILE x < number
     WHILE a = b
      x = x + 1
     WEND
    WEND
    If x = number will the outer WHILE loop notice?

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Talking

    Hi,

    You'll get an endless loop ...

    cause "WHILE x < number" will be checked only once at start ...

    only way out : a <> b AND x < Number ...



    just replace it by

    [code]

    WHILE ( x < number AND a=b )

    x = x + 1

    WEND


    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Sep 2008
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Fine. Something else.

    If there is

    Code:
    WHILE number < 3000
     number = number + 1
    WEND
    Is number = 2999 or 3000 when the loop ends? What About REPEAT...UNTIL?

  4. #4
    Join Date
    Aug 2008
    Location
    British Columbia, Canada
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Security View Post
    Fine. Something else.

    If there is

    Code:
    WHILE number < 3000
     number = number + 1
    WEND
    Is number = 2999 or 3000 when the loop ends? What About REPEAT...UNTIL?
    The code will see 2999 as less than 3000, therefore it will increment as per the next line, so when the loop ends you have number=3000.
    -Justin

  5. #5
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Code:
    WHILE number < 3000
     number = number + 1
    WEND
    Code:
    REPEAT
     number = number + 1
    UNTIL number = 3000
    If you entered each above code sections with number < 3000, these two conditional loops would operate identically, and number would be incremented until number = 3000.

    BUT, if you entered with number > 2999 Then...
    - The WHILE..WEND would not execute, and number would remain the same.
    - The REPEAT..UNTIL loop would execute 1 time, and number would be incremented by 1.

    HTH,
    SteveB
    Last edited by SteveB; - 7th September 2008 at 05:50. Reason: Amplifacation of first sentence.

  6. #6
    Join Date
    Sep 2008
    Posts
    19


    Did you find this post helpful? Yes | No

    Exclamation

    Quote Originally Posted by SteveB View Post
    Code:
    WHILE number < 3000
     number = number + 1
    WEND
    Code:
    REPEAT
     number = number + 1
    UNTIL number = 3000
    If you entered each above code sections with number < 3000, these two conditional loops would operate identically, and number would be incremented by 1.

    BUT, if you entered with number > 2999 Then...
    - The WHILE..WEND would not execute, and number would remain the same.
    - The REPEAT..UNTIL loop would execute 1 time, and number would be incremented by 1.

    HTH,
    SteveB
    The first one is what my experience also showed. So everything is fine.

    The code will see 2999 as less than 3000, therefore it will increment as per the next line, so when the loop ends you have number=3000.
    That is what I experienced.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Hi, Security

    Just remember the "number" is checked at WHILE and UNTIL lines ( where you write the test ) and it bails out ( if test true ) just after.

    Alain

    Mikroelektronika manuals ( basic and C ) have a very nice explanation of that ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Sep 2008
    Posts
    19


    Did you find this post helpful? Yes | No

    Wink

    Hi, Acetronics

    Just remember the problem is solved.

    Security

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    Ok, well noted ...

    Read you soon... new member.

    Alain
    Last edited by Acetronics2; - 8th September 2008 at 13:38.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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. LOTS of questions....
    By reaper0995 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd March 2008, 17:00
  4. While Wend
    By DJEE in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th July 2007, 08:34
  5. Pulsin versus While Wend
    By Toley00 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th March 2006, 20:08

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