Learn Java Tutorial for Beginners (Video), Part 6: If

A tutorial on the if() statement, plus some stuff on using break to break out of loops.

When the video is running, click the maximize button in the lower-right-hand corner to make it full screen.



Code for this tutorial:


public class Application {
    public static void main(String[] args) {
        
        // Some useful conditions:
        System.out.println(5 == 5);
        System.out.println(10 != 11);
        System.out.println(3 < 6);
        System.out.println(10 > 100);
        
        // Using loops with "break": 
        int loop = 0;
        
        while(true) {
            System.out.println("Looping: " + loop);
            
            if(loop == 3) {
                break;
            }
            
            loop++;
        
            System.out.println("Running");
        }
    }
}





true
true
true
false
Looping: 0
Running
Looping: 1
Running
Looping: 2
Running
Looping: 3