Skip to lesson
Westlake RoboticsLearn
Vault

FIRST Tech Challenge

Loading progress…

  • What an OpMode Does
  • Variables, Types, and Units
  • If Statements and Loop Flow
  • Methods, Classes, and Helpers
  • Enums, Lists, and Team Vocabulary

If Statements and Loop Flow

Use decisions and loops to make robot behavior conditional and safe.

Java Foundations for FTCFoundations

In this lesson, you will:

  • Explain if statements and loop flow in FTC robot terms.
  • Connect the Java idea to telemetry or hardware behavior.
  • Write a small test that proves the concept before using it in match code.

Concept narrative

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.

Robot mental model

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.

Implementation walkthrough

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.

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);

Common mistakes and debugging

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.

Practice

Write a drivetrain snippet with normal drive, slow mode, and an emergency stop button. Telemetry must show the selected mode.

Checkpoint

  • Every branch has a named mode.
  • Emergency stop wins over slow/normal drive.
  • Telemetry proves the active branch.
  • The test record includes the setup, prediction, and observed result.
  • A teammate can repeat the check from the saved evidence without guessing.

Reflection check

Check your understanding before moving on.

Slow mode and an emergency-stop button are both pressed. What must the control flow guarantee?
Why publish a readable drive-mode label in telemetry?

0 of 2 answered

References

Learn Java for FTCFTC-focused Java book and exercises by Alan G. Smith.FIRST FTC DocsOfficial SDK, Robot Controller, and programming reference.Game Manual 0FTC community reference for programming, controls, and robot design.
Loading lesson progress
Previous lessonVariables, Types, and UnitsNext lessonMethods, Classes, and Helpers