Provide Best Programming Tutorials

The if-then Statement

The if-then Statement

The if-then statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates to true.

This logic is really simple. if the condition return true then execute the code block.

    //statement to execute

The condition can only be true or false.

Look at the example below since a<b is true then the code inside the curly braces will be executed.

public static void showIf() {
     int a = 10;
     int b = 20;
     if (a < b) {
         System.out.println("a is less than b!");

The output is:

a<b is true

Leave a Reply

Close Menu