Auton with sensors

So this year I’m gonna get out of my comfort zone a little bit and use something other than a time-based autonomous; instead, using sensors. How would I have the condition set up: in a while(condition) loop or if(condition) statement?

I think I used both for the shaft encoders. I can’t remember

@Jake_B it really depends, but in general, most of the time you need to monitor your sensors continuously (repetitively enough) during the operation. Single “if()” is, uh, single, so you’re likely going to use inside a loop. In reality, you can rewrite pretty much any language construct by an infinite loop and some if()s with break.
So for quadrature encoder example, your operation could be either of (pseudocode with varying degree of complexity and functionality):
*)


setSpeed(...);
waitUntil(getEncoderValue() > 300);  // this is in fact a hidden loop, check NatLang_CORTEX.c
stop();

*)

resetEncoders();
setSpeed(...)
for (;;) { // that's my infinite loop
    // do some other stuff here
    ...]
    // Are we there yet?
    if (getEncoderValue() > 300) break;
}
stop();

*)

while (getEncoderAverage() < 300) {
    int delta = getLeftEncoder() - getRightEncoder();
    setLeftSpeed(speed-delta);
    setRightSpeed(speed+delta);
}
stop();