Computer Applications

What is conditional flow of control? Explain with an example.

Java Conditional Stmts

9 Likes

Answer

By default, the statements of a program are executed sequentially from top to bottom in order in which they are written. But most of the times our programs require to alter this top to bottom control flow based on some condition. When the flow of control of a program is changed based on some condition using control statements, it is termed conditional flow of control. For example, in the below program we achieve conditional flow of control using the if-else statement.


public class ConditionalExample {
    public static void main(String args[]) {
        int x = -10;
        if (x >= 0) {
            System.out.println("Positive Number");
        }
        else {
            System.out.println("Negative Number");
        }
    }
}

Answered By

4 Likes


Related Questions