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…

Java-Switch Statement

Switch Statement The switch statement is provides a better alternative than a large series of if-else-if statements. Here is its general form: The expression must be of type byte, short, int, or char; each of the values specified in the case statements must be of a type compatible with the expression. Each case value must … Read more…