Syntax for until command in C program?

Hey!

I'm building an wall following bot using IR sensors and dc motors. I got my bot following inbetween 2 walls. Now i want the bot to follow a single wall ie either a wall to the left of the bot or to the right of the bot. Say if the wall is on the right side of the bot, i want the bot to turn left until the sensor value changes to a particular value. Is there a command in c program to acheive this?

There are a few ways to do

There are a few ways to do this, but ‘for’ and ‘while’ loops are probably the most convenient. An example would be:

while(!(sensor==value))
{
turnLeft();
sensor=checkSensor();
}

In this example, the while statement tests to see if ‘sensor’ is equal to ‘value’, and if it is not equal then the contents of the loop will be executed. In this case I’ve just included two dummy functions to turn left and then check the sensor again - the contents of your loop may be somewhat different. The important part is that until ‘sensor’ and ‘value’ are the same, the loop will repeat forever.

**do { **

do {
turnLeft();
sensor=checkSensor();
} while(!(sensor==value));

 

should also work, in case you want the loop to execute at least once. On a side note, if that’s an analog sensor you probably want (sensor <= value) or (sensor >= value) or maybe a combination of the two.