If Statements and Loop Flow
Use decisions and loops to make robot behavior conditional and safe.
Use decisions and loops to make robot behavior conditional and safe.
In this lesson, you will:
Control flow is how robot code chooses behavior. If statements decide whether slow mode is active, whether an arm may move, whether autonomous should advance, or whether a sensor reading is safe enough to trust.
This lesson should be read as a robotics lesson first and a programming lesson second. The code matters because it lets the team create repeatable behavior under match pressure. Students should slow down long enough to name the inputs, outputs, assumptions, and safety limits before they touch the robot.
A robot loop is a repeated conversation: read the world, decide, command hardware, report telemetry. Students should avoid thinking of the loop as a place to paste random snippets. Every decision should have an input, a reason, and an observable result.
A good mental model gives the team a shared language. When a driver, builder, and programmer can point to the same behavior and use the same words, debugging gets calmer and code review becomes useful instead of personal.
Walk through one decision at a time. Start with a slow-mode condition, then add a safety stop, then print which branch was selected. Avoid nested conditions until the first branch can be explained by a driver.
Keep the implementation staged. First create the smallest version that compiles. Then add telemetry that proves it is running. Then connect one hardware device or one decision. Finally, repeat the test from a cold init so the team knows it was not a lucky hot reload.
IfStatementsandLoopFlow.javaJava
String driveMode = "normal";
double scale = 0.85;
if (gamepad1.left_bumper) {
driveMode = "slow";
scale = 0.35;
}
if (gamepad1.b) {
driveMode = "emergency stop";
scale = 0.0;
}
telemetry.addData("drive mode", driveMode);Decision bugs often come from overlapping conditions or missing else branches. If two branches can both command the same motor, the last one wins. Print mode names so students can see which branch is active.
Use the five-value debugging habit: input, state, target, measurement, output. If one of those values is missing, add it before rewriting logic. The goal is to make the robot tell the truth about what it thinks is happening.
Check your understanding before moving on.
What is the FTC reason to learn if statements and loop flow?
0 of 1 answered
Mark this lesson complete — “Methods, Classes, and Helpers” is up next.