View Full Version : Do ... Until ... Loop

01-16-2003, 03:27 PM
The syntax I used for a Do .. until ... loop -

Do Until (sFront = 0)



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


This debugs "Im Trapped, Help Me!"

Thanks in advance,

01-16-2003, 03:48 PM
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


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,

01-16-2003, 03:56 PM
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!

01-19-2003, 12:16 AM
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++

01-19-2003, 01:46 AM
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


uses = as the assignment operator.

01-19-2003, 08:52 AM
(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...