1. What is Control Flow?
Control flow refers to the order in which statements are executed in a program.
Normally, Java executes statements one by one, from top to bottom. This is called sequential execution.
Example:
public class Main { public static void main ( String [ ] args ) { System . out . println ( "Start" ) ; System . out . println ( "Learning Java" ) ; System . out . println ( "End" ) ; } }
Enter fullscreen mode
Exit fullscreen mode
Output:
Start Learning Java End
Enter fullscreen mode
Exit fullscreen mode
But in real-world applications, we sometimes need to make decisions based on conditions. For example, an ATM should allow a withdrawal only when the account has sufficient balance.
This is where control flow statements are useful.
2.…