Bodhak java looping Statements tutorial in this topic we have covered the conditional statements if switch statements. Looping statements like while for …
Java, like all other programming languages, is equipped with speciﬁc statements that allow us to check a condition and execute certain parts of code depending on whether the condition is true or false. Such statements are called conditional statements.
java looping Statements tutorial
The if statement followed by a conditional statement. The given conditional statement is evaluated it returns a Boolean value.
If it returned value is true the following statement(s) are executed.
If returned value is false the If statement is ignored and execution control moves to the next following statement
Statement If followed by a conditional statement. The given conditional statement is evaluated it returns a Boolean value.
If returned value is true the following statement(s) are executed.
If returned value is false the If statement(s) followed by else is executed.
A nested if statement is an if-else statement with another if statement as the if the body or the else body.
switch statement provides another way to choose the next action
The switch statement evaluates an expression, then attempts to match the result to one of a series of values
Execution transfers to statement list associated with the first value that matches
switch Statement rules:
The expression must evaluate to an integral value, such as an integer character or strings.
The break statement is usually used to terminate the statement list of each case, which causes control to jump to the end of the switch statement and continue.
A default case can be added to the end of the list of cases and will execute if no other case matches
A while loop is a control structure that allows you to repeat a task a certain number of times.
When executing, if the Boolean expression result is true, then the statements inside the loop will be executed. This will continue as long as the expression result is true.
Here, the key point of the while loop is that the loop might not ever run. When the expression is tested and the result is false, the loop body will be skipped and the next statement of the while loop will be executed hence it is known as Entry Control Loop statement