A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/javaexamples/method_break.htm below:

How to use break to jump out of a loop in a method using Java

How to use break to jump out of a loop in a method using Java Problem Description

How to use break to jump out of a loop in a method?

Solution

This example uses the 'break' to jump out of the loop.

public class Main {
   public static void main(String[] args) {
      int[] intary = { 99,12,22,34,45,67,5678,8990 };
      int no = 5678;
      int i = 0;
      boolean found = false;
      
      for ( ; i < intary.length; i++) {
         if (intary[i] == no) {
            found = true;
            break;
         }
      }
      if (found) {
         System.out.println("Found the no: " + no + " at  index: " + i);
      } else {
         System.out.println(no + "not found  in the array");
      }
   }
}
Result

The above code sample will produce the following result.

Found the no: 5678 at  index: 6

java_methods.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4