Break and Continue Statements

Lesson Details:
July 10, 2020


I: Introduction

In this article I will introduce you to Java programming language. Java is a high level programming language that was developed at Sun Microsystems in the 1990s. It is a multi-paradigm language, meaning that it allows you to use different programming techniques and styles. Java is a portable language, meaning that it can be used on many different platforms including Windows, Linux, Mac OSX and others. It is also object orientated, meaning that all data in the program is stored in objects rather than simple variables. In this article I will give you a brief introduction to the Java programming language.

II: Body

In this section I will discuss some of the features of the Java programming language.

Break and Continue Statements

In Java, break and continue statements are used to stop or continue your code from executing if certain conditions are true. The syntax for both break and continue statements is:

break;

or:

continue;

When using either of these statements, you must know which 'block' of code the statement is referring to. A block of code is any set of instructions between { and }, such as:

{

}

The block of code inside the curly brackets above can contain many instructions separated by semi-colons (;). A statement like the following would only execute every two instructions:

for(int i=0;i<9;i++) {

System.out.println("Hello");

}

This code would output: Hello! . If we used a break statement after the first semi-colon, we would get: Hello!Hello! instead:

for(int i=0;i<9;i++) {

System.out.println("Hello");













































































loader
Course content