View Full Version : Regarding WHILE...WEND
Security
- 6th September 2008, 20:00
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:
WHILE x < number
WHILE a = b
x = x + 1
WEND
WEND
If x = number will the outer WHILE loop notice?
Acetronics2
- 6th September 2008, 20:30
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
Security
- 7th September 2008, 00:23
Fine. Something else.
If there is
WHILE number < 3000
number = number + 1
WEND
Is number = 2999 or 3000 when the loop ends? What About REPEAT...UNTIL?
greensasquatch
- 7th September 2008, 01:17
Fine. Something else.
If there is
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.
SteveB
- 7th September 2008, 02:15
WHILE number < 3000
number = number + 1
WEND
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
Security
- 7th September 2008, 03:45
WHILE number < 3000
number = number + 1
WEND
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.
Acetronics2
- 7th September 2008, 09:22
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
Security
- 7th September 2008, 20:11
Hi, Acetronics
Just remember the problem is solved.
Security
Acetronics2
- 8th September 2008, 09:31
Hi,
Ok, well noted ...
Read you soon... new member.
Alain
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.