Java-Nested For Loop

Nested For Loop The placing of one loop inside the body of another loop is called nesting.  When you nest two loops, the outer loop takes control of the number of complete repetitions of the inner loop. Program Program Source class Javaapp { public static void main(String[] args) { for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { System.out.print(” … Read more…

Java-For Loop with Multiple Conditions

For Loop with Multiple Conditions The for loop has several capabilities that are not found in other loop constructs. For example, more than one variable can be initialized at a time in the for statement using comma. The test condition may have any compound relation. For example, in the following program, the expression1  has two parts … Read more…

Java-Control Infinite Loop

Control Infinite Loop Using Break If you can force immediate termination of a loop, bypassing the conditional expression and any remaining code in the body of the loop. When a break statement is encountered inside a loop, the loop is terminated and program control resumes at the next statement following the loop. The break statement can be used with … Read more…

Java-Infinite For Loop

Infinite For Loop You can intentionally create an infinite loop, if you leave all three parts of the for empty. The general form is: This loop will run forever because there is no condition under which it will terminate. Although there are some programs, such as operating system command processors, that require an infinite loop, most “infinite … Read more…

Java-For Loop

For Loop The for loop is usually used when the number of iterations is predetermined. The format of the for loop is : First executed expression1 is only once before looping, then executed expression2,  expression2 is a conditional or boolean expression, if the condition is true, then the body of the statements is executed. After execution … Read more…

Java-Do While Loop

Do While Loop The do-while loop always executes its body at least once, because its conditional expression is at the bottom of the loop. Its general form is : The do-while loop first executes the body of the loop and then evaluates the conditional expression. If this expression is true, the loop will repeat. Otherwise, the loop terminates. … Read more…