0% found this document useful (0 votes)
1 views16 pages

Updated Control Statements in Java

CONTROL STATEMENT INJAVA

Uploaded by

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

Updated Control Statements in Java

CONTROL STATEMENT INJAVA

Uploaded by

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

CONTROL STATEMENTS IN JAVA

• Presented by: [Your Name]


• Date: [Add Date]
Introduction to Control Statements
• Used to control the flow of execution in a
program.
• Types:
• - Conditional Statements
• - Looping Statements
• - Jump Statements
Conditional Statements
• - if statement
• - if-else statement
• - else-if ladder
• - switch statement
if Statement
• Syntax:
• if (condition) {
• // code to execute if condition is true
• }
• Example:
• if (a > b) {
• System.out.println("A is greater");
• }
if-else Statement
• Syntax:
• if (condition) {
• // true block
• } else {
• // false block
• }
• Example:
• if (a % 2 == 0)
• System.out.println("Even");
else-if Ladder
• Syntax:
• if (condition1) {
• // code
• } else if (condition2) {
• // code
• } else {
• // default code
• }
switch Statement
• Syntax:
• switch (expression) {
• case value1: // code; break;
• ...
• default: // code;
• }
• Used when multiple conditions are based on a
single variable.
Looping Statements
• - for loop
• - while loop
• - do-while loop
• Used to repeat a block of code multiple times.
for Loop
• Syntax:
• for (int i = 0; i < 5; i++) {
• System.out.println(i);
• }
• Used when number of iterations is known.
while Loop
• Syntax:
• int i = 0;
• while (i < 5) {
• System.out.println(i);
• i++;
• }
do-while Loop
• Syntax:
• int i = 0;
• do {
• System.out.println(i);
• i++;
• } while (i < 5);
• Executes at least once.
Jump Statements
• - break – exits loop or switch.
• - continue – skips to next iteration.
• - return – exits from a method.
Example with break and continue
• Example:
• for (int i = 1; i <= 5; i++) {
• if (i == 3) continue;
• System.out.println(i);
• }
Summary
• - Control statements manage program flow.
• - Help in decision making, repetition, and
redirection.
• - Essential for logic building in Java.
Thank You
• Questions?
• Feel free to ask!
Types of Control Statements
• 1. if statement
• 2. if-else statement
• 3. while statement
• 4. do...while statement
• 5. switch case statement
• 6. for loop

You might also like