DAY4 Notes
DAY4 Notes
QUESTIONS(Theory)
The break statement is used to terminate the loop immediately. The continue statement is used to
skip the current iteration of the loop.
The continue statement applies only to loops, not to a switch statement. A continue inside a switch
inside a loop causes the next loop iteration. Using continue statement in switch case will throw an
error because continue statement takes control to the condition checking statement again.
Control statements in Java manage the flow of program execution. They include decision-making (if-
else, switch), looping (for, while, do-while), and branching (break, continue, return) constructs.
The ‘for loop’ is a control flow statement that allows code to be executed repeatedly based on a
given boolean condition. It is particularly useful for iterating over arrays or collections and executing
a block of code a specific number of times.
The for loop provides an efficient way to iterate over a range of values, execute code multiple times,
or traverse arrays and collections.
The default keyword is used to specify the set of statements to execute if there is no case match. It is
optional to use the default keyword in a switch case. Even if the switch case statement does not
have a default statement, it would run without any problem.
Use a for loop when the number of iterations is known or when iterating over a range of
values.
Use a while loop when the number of iterations is uncertain or when looping based on a
condition that may change during execution.