answersLogoWhite

0


Best Answer

The break keyword is used to prematurely exit the current block of code. Java only allows it to be used in the body of a loop or switch, and is helpful when you want a special reason to stop executing that code.

Here is an example, in which we will search through an array of integers for a particular value. If that value is found, we will print out its location in the array and then stop running.

void search(int num, int[] array) {

// Store the position of num in array (or -1 if it wasn't found)

int position = -1;

// Here is our search loop

for(int i = 0; i < array.length; ++i) {

if(array[i] == num) {

// If we find the number, store its position and exit the loop

position = i;

break;

}

}

// Print out our results

if(position >= 0) {

System.out.println(num + " found at position: " + position);

}else {

System.out.println(num + " was not found in the array");

}

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the function of break in java programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is a java programming?

A java program is a program that is coded and run in the programming language called java. Java is similar to c++ in structure, and is more common in web apps. C++ is the equivalent for more heavy duty programs such as most software used to compose a java program.


What is the first name before of the Java Programming?

The first name of the Java Programming was Oak. It then went by the game Green and finally Java from Java coffee.


Sorting of array through function in java programming?

// the build in sorting functions in Java will sort pretty much any array // of Comparable objects or primitives Arrays.sort(someArray);


What is meant by the term SetTimeOut?

SetTimeOut is a term that is used in Java programming. It refers to the time it takes for a function in a program to time out or stop. SetTimeOut is a vital function.


What is a hash function in java?

http://www.partow.net/programming/hashfunctions/ please refer this website. i think its the best so far


Is java DBMS?

no, Java is not dbms.. Java is a programming language Dbms is database


What is java card?

Java Card is a Java platform for programming smart cards.


Is the best institute for learn java programming in Pakistan?

The Java programming language is a general-purpose computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. Then you learn java programming language in Pakistan get the best java programming classes at the lowest cost.


What is the pane in which the Java programming statements are located called?

The pane in which the Java programming statements are located is called


What are the features in java that makes it similar to C programming?

Java is not similar to C. Java is, however, similar to C++. Both C++ and Java are object orientated programming languages (OOPL's).


What is unicode in java?

Java Supports International programming so java supports Unicode


What has the author Jaime Nino written?

Jaime Nino has written: 'Introduction to Programming and OOD Java' 'An introduction to programming and object-oriented design using JAVA' -- subject(s): Java (Computer program language), Object-oriented programming (Computer science) 'Introduction to Programming and OOD Using Java'