Computer Science, asked by sindhusharavuri, 1 year ago

If else if condition and while loop
explain it by writing a program of each
can take any example
(IP)

Answers

Answered by shubhi1638
0
Java if..else..if Statement

In Java, it's possible to execute one block of code among many. For that, you can use if..else...if ladder.

if (expression1) { // codes } else if(expression2) { // codes } else if (expression3) { // codes } . . else { // codes }

The if statements are executed from the top towards the bottom. As soon as the test expression is true, codes inside the body of that if statement is executed. Then, the control of program jumps outside if-else-if ladder.

If all test expressions are false, codes inside the body of else is executed.

Example 3: Java if..else..if Statement

class Ladder { public static void main(String[] args) { int number = 0; if (number > 0) { System.out.println("Number is positive."); } else if (number < 0) { System.out.println("Number is negative."); } else { System.out.println("Number is 0."); } } }

When you run the program, the output will be:

Number is 0.

When number is 0, both test expression number > 0 and number < 0 is evaluated to false. Hence, the statement inside the body of else is executed.

The above program checks whether number is positive, negative or 0.


diagram above✓✓

While loop flow diagram

In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.


Attachments:
Answered by ratheemimansha
0

Answer:

oops you got the answer....

Explanation:

if you will follow me I will definitely follow u back

Similar questions