0% found this document useful (0 votes)
3 views

DAY4 Notes

The document discusses control statements in Java, including break, continue, if-else, loops (for, while, do-while), and switch cases. It explains the differences between break and continue, the execution process of for loops, and the distinctions between while and do-while loops. Additionally, it covers the use of the default keyword in switch statements and when to use for versus while loops.

Uploaded by

tikitakam40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

DAY4 Notes

The document discusses control statements in Java, including break, continue, if-else, loops (for, while, do-while), and switch cases. It explains the differences between break and continue, the execution process of for loops, and the distinctions between while and do-while loops. Additionally, it covers the use of the default keyword in switch statements and when to use for versus while loops.

Uploaded by

tikitakam40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

DAY4:

1. if/else if , 2.Loopings(for, while, do-while), 3.Switch case, 4.break/continue

QUESTIONS(Theory)

1. What is difference between break and continue?

The break statement is used to terminate the loop immediately. The continue statement is used to
skip the current iteration of the loop.

2. Whether we can use continue statement in switch?

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.

3. What is mean by control statements and types?

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.

4. What is mean by for loop?

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.

5. Can you explain about for loop execution process?

The for loop provides an efficient way to iterate over a range of values, execute code multiple times,
or traverse arrays and collections.

6. What is difference between while and do-while?

 while loop is entry controlled loop.


 do-while loop is exit controlled loop.

7. What is the use of default keyword in switch?

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.

8.Difference between for and while loop?

 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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy