View Full Version : Do ... Until ... Loop
The syntax I used for a Do .. until ... loop -
Do Until (sFront = 0)
'code
Loop
This creates an infinite loop that I cant get out of, even if sFront = 0. What gives?
In fact, I also tested to see if the value of sFront isn't changing with -
Do Until (sFront = 0)
If sFront = 0 then DEBUG "Im Trapped, Help Me!",CR
Loop
This debugs "Im Trapped, Help Me!"
Thanks in advance,
Actually, I have a more specific question. As I was reading the documentation that came with PBASIC 2.5 I noticed that the Do ... While ... Loop needs a condition with the WHILE and UNTIL, whereas statements are used where the code is inserted.
Do While|Until conditions
'code
statements
Loop While|Until conditions
Question - What is the difference between a condition and a statement ? Can I use sFront = 0 as a condition?
Thanks again,
Hey, I figured out why the code was not working to my liking. In my code, I used a SEROUT, but no SERIN. Remember, you need to use a SERIN to get input from the sensors! This goes to show what sleep deprivation does to people!
perhaps, ur reassigning
sFont = 0 everytime u loop
mayb im wrong, how about some logical operators instead /
sFont == 0
meh ... forget me ... im still stuck in C++
No, == is not a valid operator in PBASIC.
Goya's third post hit the nail on the head: if you don't SERIN, you don't get any new data.
As for what makes an expression a condition is the presence of any of the following operators:
=
>(=)
<(=)
<>
Note that = can also be used for assignment. It's function is determined by the context in which it is used. For example:
if rc_sw1=1 then ...
uses = as a comparison operator, whereas
rc_sw1=1
uses = as the assignment operator.
(sFront = 0)
that should just be sFront = 0
also before the main programming loop you should put sFront = 0 or something like that to tell pbasic what the value for it is...
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.