Skip to content
Preview · sample content · Explore all pages

Values and control flow

Last updated: 28 Sept 20264 min read
guide
By AITrove Editorial

Represent values with types and use branches and loops to choose the work to run.

Variables and branches

A variable has a type and a value. A condition selects which branch executes.

Java
int score = 72;
if (score >= 50) {
    System.out.println("Pass");
} else {
    System.out.println("Try again");
}

Practice

Change the score to 49 and predict the output. Then write a loop that prints the values from 1 through 5.

Connected lessons

Continue with Java arrays and bounds, Java Tutorial.

Common Mistakes

Check empty inputs and invalid values before applying this operation to application data. State whether a method edits shared state or returns a separate value.

java
Storage details