WestlakeLEARN
FTC · Java

FIRST Tech Challenge

FTC · Java

  • 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.

Module 1: Java Foundations for FTCFoundations

In this lesson, you will:

  1. 01Explain if statements and loop flow in FTC robot terms.
  2. 02Connect the Java idea to telemetry or hardware behavior.
  3. 03Write 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.

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.

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.

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.

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.

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

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.

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.

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.

Reflection check

Check your understanding before moving on.

What is the FTC reason to learn if statements and loop flow?

0 of 1 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.

Finished reading?

Mark this lesson complete — “Methods, Classes, and Helpers” is up next.

Variables, Types, and UnitsMethods, Classes, and Helpers