Labeled Loop in Java12 May 2025 | 3 min read In programming, a loop is a sequence of instructions that is continually repeated until a certain condition is met. In this section, we will discuss the labeled loop in Java with examples. What is a labeled loop in Java?A label is a valid variable name that denotes the name of the loop to where the control of execution should jump. To label a loop, place the label before the loop with a colon at the end. Therefore, a loop with the label is called a labeled loop. In layman terms, we can say that label is nothing but to provide a name to a loop. It is a good habit to label a loop when using a nested loop. We can also use labels with continue and break statements. There are three types of loop in Java:
Let's discuss the above three loops with labels. Java Labeled for LoopLabeling a for loop is useful when we want to break or continue a specific for loop according to requirement. If we put a break statement inside an inner for loop, the compiler will jump out from the inner loop and continue with the outer loop again. What if we need to jump out from the outer loop using the break statement given inside the inner loop? The answer is, we should define the label along with the colon(:) sign before the loop. Syntax: Let's see an example of labeled for-loop. LabeledForLoop.java Output: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 Java Labeled while LoopSyntax: LabledWhileLoop.java Output: outer value of i= 0 inner value of i= 1, j= 0 outer value of i= 1 outer value of i= 2 outer value of i= 3 outer value of i= 4 |
An algorithm that does the mapping of data to a hash of fixed size is called the hashing algorithm. Hashing algorithm in Java is a cryptographic hash function. A hash algorithm or hash function is designed in such a way that it behaves like a one-way...
9 min read
? In Java, the cast operator is used to convert a value from one data type to another. It is denoted by the parenthesis's operator "()". Syntax: DataType variableName = (DataType) value; Within the brackets, the cast operator is used to change the value to the chosen data type. The...
4 min read
Niven numbers are named after Ivan Niven, a Canadian mathematician who introduced them in a paper in 1977. However, they were first studied by the Indian mathematician D. R. Kaprekar in the 1950s. In this section, we will learn what is niven number with example and...
5 min read
Generating a random string in Java is a simple concept which is often required to build Ids, temporary passwords, session tokens or any other case where the alphanumeric string is most electronically required. There are several ways to achieve this using the different classes and...
13 min read
In this section, we will learn what is equilibrium index in an array and how to find the equilibrium index through a Java program. Equilibrium Index If the sum of lower indices elements is equal to the sum of higher indices elements is called an equilibrium index of...
4 min read
defines the connection between two classes that are set up through their objects. Association manages one-to-one, one-to-many, and many-to-many relationships. In Java, the multiplicity between objects is defined by the Association. It shows how objects communicate with each other and how they use the functionality...
9 min read
In this section, we will discuss what is pandigital number along with their versions and also create Java programs to check if the given number is a pandigital number or not. The pandigital number program frequently asked in Java coding interviews and academics. Pandigital Number A 10-digit integer...
4 min read
Combinatorics' basic idea of permutations is the arrangement of a collection of items in several orders. We'll go through several techniques for creating permutations in Java and include code samples along with thorough explanations. How Do Permutations Occur? A permutation is the organization of elements in a particular...
6 min read
Titaniry operation, also known as ternary operator or conditional operator, is a shorthand notation for an if-else assertion in Java. It provides a concise way of writing easy conditional statements in Java. In this newsletter, we are able to discover the syntax of the ternary operator,...
4 min read
In Java, bitwise operators are used to execute binary number bit-level operations. These operators alter the bits in a number by performing operations like bit shifting, AND, OR, NOT, and XOR. With examples and programs, we will go over the various types of bitwise operators...
5 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India