Control flow Statements
Control flow Statements
Answer: Control flow refers to the order in which statements in a program are executed. It’s essential for
defining the logic and sequence of operations in a program.
Answer: The primary categories of control flow in Java are conditional statements, loops, and method
calls.
Answer: The nested if statement represents the if block within another if block. Here, the inner if block
condition executes only when outer if block condition is true.
Syntax:
1. if(condition){
2. //code to be executed
3. if(condition){
4. //code to be executed
5. }
6. }
Answer: The ‘break’ statement is used to exit the ‘switch’ statement after a case is executed.
Answer: The Java do-while loop is used to iterate a part of the program repeatedly, until the specified
condition is true. But The Java do-while loop is executed at least once because condition is checked after
loop body.
Syntax:
1. do{
2. //code to be executed / loop body
3. //update statement
4. }while (condition);
16. Explain the ‘break’ statement in Java and its role in control flow?
Answer: The Java break statement is used to break loop or switch statement. It breaks the current flow
of the program at specified condition. In case of inner loop, it breaks only inner loop.
17. What is the ‘continue’ statement in Java, and how does it affect loop execution?
Answer: The ‘continue’ statement is used to skip the current iteration of a loop and proceed to the next
iteration without executing the remaining code in the current iteration.
18. What is a return statement in Java?
Answer: the return statement is used for returning a value when the execution of the block is completed.
Answer: The Java comments are the statements in a program that are not executed by the compiler and
interpreter.
1. Single Line Comment – these comments are used to comment only one line. Single line comments
starts with two forward slashes (//).
2. Multi Line Comment -are used to comment multiple line of code. Multi-line comments are placed
between /* and */.
3. Documentation Comment – is used to create documentation API. To create documentation API, You
need to use Javadoc tool. The documentation comments are placed between /** and */.