SlideShare a Scribd company logo
BON SECOURS COLLEGE FOR WOMEN
THANJAVUR
DEPARTMENT OF INFORMATION
TECHNOLOGY
Dr.R.SUGANYA
Head & Asst.Professor
Bon Secours College for Women
Thanjavur
PROGRAMING IN JAVA
CONTROL STRUCTURE
CONTROL STRUCTURE
There are three types in Java:
 If/else/else if, ternary operator and switch.
 Loops that are used to iterate through multiple values/objects
and repeatedly run specific code blocks.
 The basic loop types in Java are for, while and do while.
 Branching Statements, which are used to alter the flow of
control in loops
There are three kinds of control structures:
• Conditional Branches, which we use for choosing
between two or more paths. There are three types in
Java: if/else/else if, ternary operator and switch.
• Loops that are used to iterate through multiple
values/objects and repeatedly run specific code
blocks. The basic loop types in Java are for, while and do
while.
• Branching Statements, which are used to alter the flow of
control in loops. There are two types in
Java: break and continue.
2. If/Else/Else If
• The if/else statement is the most basic of control structure
but can also be considered the very basis of decision making
in programming.
• While if can be used by itself, the most common use-
scenario is choosing between two paths with if/else:
if (count > 2) { System.out.println("Count is higher than 2"); }
else { System.out.println("Count is lower or equal than 2");
}Theoretically, we can infinitely chain or nest if/else blocks
but this will hurt code readability, and that's why it's not
advised.
• We'll explore alternative statements in the rest of this
article.
3. Ternary Operator
• We can use the ternary operator as a shorthand expression that
works like an if/else statement.
• Let's see our if/else example again:
• if (count > 2) { System.out.println("Count is higher than 2"); }
else { System.out.println("Count is lower or equal than 2"); }We
can refactor this with a ternary as follows:
• System.out.println(count > 2 ? "Count is higher than 2" : "Count
is lower or equal than 2");While ternary can be a great way to
make our code more readable, it isn't always a good substitute
for if/else.
4.Switch
• If we have multiple cases to choose from, we can use
a switch statement.
• Let's again see a simple example:
• int count = 3; switch (count) { case 0:
System.out.println("Count is equal to 0"); break; case 1:
System.out.println("Count is equal to 1"); break; default:
System.out.println("Count is either negative, or higher
than 1"); break; }Three or more if/else statements can be
hard to read. As one of the possible workarounds, we can
use switch, as seen above.
5.Loops
• We use loops when we need to repeat the same code
multiple times in succession.
• Let's see a quick example of
comparable for and while type of loops:
• for (int i = 1; i <= 50; i++) { methodToRepeat(); } int
whileCounter = 1; while (whileCounter <= 50) {
methodToRepeat(); whileCounter++; } Both code blocks
above will call methodToRepeat 50 times.
6. Break
• We need to use break to exit early from a loop.
• Let's see a quick example:
• List<String> names = getNameList(); String name = "John
Doe"; int index = 0; for ( ; index < names.length; index++) { if
(names[index].equals(name)) { break; } }Here, we are looking
for a name in a list of names, and we want to stop looking
once we've found it.
• A loop would normally go to completion, but we've
used break here to short-circuit that and exit early.
7. Continue
• Simply put, continue means to skip the rest of the loop we're
in:
• List<String> names = getNameList(); String name = "John
Doe"; String list = ""; for (int i = 0; i < names.length; i++) { if
(names[i].equals(name)) { continue; } list += names[i]; }Here,
we skip appending the duplicate names into the list.
Different control structure:
 The basic Control Structures in programming languages are:
Conditionals (or Selection):
 which are used to execute one or more statements if a
condition is met. Loops (or Iteration):
 which purpose is to repeat a statement a certain number of
times or while a condition is fulfilled.
Control statements in Java:
• Decision Making Statements.
• Simple if statement.
• if-else statement.
• Nested if statement.
• Switch statement.
• Looping statements.
• While.
• Do-while.

More Related Content

Similar to JAVA.pptx

JAVA LOOP.pptx
JAVA LOOP.pptxJAVA LOOP.pptx
JAVA LOOP.pptx
SofiaArquero2
 
javaloop understanding what is java.pptx
javaloop understanding what is java.pptxjavaloop understanding what is java.pptx
javaloop understanding what is java.pptx
RobertCarreonBula
 
CPP04 - Selection
CPP04 - SelectionCPP04 - Selection
CPP04 - Selection
Michael Heron
 
ch2 Python flow control.pdf
ch2 Python flow control.pdfch2 Python flow control.pdf
ch2 Python flow control.pdf
RanjanaThakuria1
 
kotlin-nutshell.pptx
kotlin-nutshell.pptxkotlin-nutshell.pptx
kotlin-nutshell.pptx
AbdulRazaqAnjum
 
02_Data Types in java.pdf
02_Data Types in java.pdf02_Data Types in java.pdf
02_Data Types in java.pdf
Parameshwar Maddela
 
plsql tutorialhub....
plsql tutorialhub....plsql tutorialhub....
plsql tutorialhub....Abhiram Vijay
 
String.pptx
String.pptxString.pptx
String.pptx
RanjithKumar742256
 
Control statements
Control statementsControl statements
Control statements
CutyChhaya
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
Tanzeel Ahmad
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
 
java basics - keywords, statements data types and arrays
java basics - keywords, statements data types and arraysjava basics - keywords, statements data types and arrays
java basics - keywords, statements data types and arrays
mellosuji
 
02basics
02basics02basics
02basics
Waheed Warraich
 
Fundamental programming structures in java
Fundamental programming structures in javaFundamental programming structures in java
Fundamental programming structures in javaShashwat Shriparv
 
ProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdf
ProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdfProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdf
ProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdf
lailoesakhan
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
DevaKumari Vijay
 
Programming Concepts
Programming ConceptsProgramming Concepts
Programming Conceptsjoshss7
 
prt123.pptx
prt123.pptxprt123.pptx
prt123.pptx
ASADKS
 

Similar to JAVA.pptx (20)

JAVA LOOP.pptx
JAVA LOOP.pptxJAVA LOOP.pptx
JAVA LOOP.pptx
 
javaloop understanding what is java.pptx
javaloop understanding what is java.pptxjavaloop understanding what is java.pptx
javaloop understanding what is java.pptx
 
CPP04 - Selection
CPP04 - SelectionCPP04 - Selection
CPP04 - Selection
 
Init() Lesson 3
Init() Lesson 3Init() Lesson 3
Init() Lesson 3
 
ch2 Python flow control.pdf
ch2 Python flow control.pdfch2 Python flow control.pdf
ch2 Python flow control.pdf
 
kotlin-nutshell.pptx
kotlin-nutshell.pptxkotlin-nutshell.pptx
kotlin-nutshell.pptx
 
02_Data Types in java.pdf
02_Data Types in java.pdf02_Data Types in java.pdf
02_Data Types in java.pdf
 
plsql tutorialhub....
plsql tutorialhub....plsql tutorialhub....
plsql tutorialhub....
 
Md04 flow control
Md04 flow controlMd04 flow control
Md04 flow control
 
String.pptx
String.pptxString.pptx
String.pptx
 
Control statements
Control statementsControl statements
Control statements
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
java basics - keywords, statements data types and arrays
java basics - keywords, statements data types and arraysjava basics - keywords, statements data types and arrays
java basics - keywords, statements data types and arrays
 
02basics
02basics02basics
02basics
 
Fundamental programming structures in java
Fundamental programming structures in javaFundamental programming structures in java
Fundamental programming structures in java
 
ProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdf
ProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdfProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdf
ProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdf
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
 
Programming Concepts
Programming ConceptsProgramming Concepts
Programming Concepts
 
prt123.pptx
prt123.pptxprt123.pptx
prt123.pptx
 

Recently uploaded

GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 

Recently uploaded (20)

GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 

JAVA.pptx

  • 1. BON SECOURS COLLEGE FOR WOMEN THANJAVUR
  • 2. DEPARTMENT OF INFORMATION TECHNOLOGY Dr.R.SUGANYA Head & Asst.Professor Bon Secours College for Women Thanjavur
  • 4. CONTROL STRUCTURE There are three types in Java:  If/else/else if, ternary operator and switch.  Loops that are used to iterate through multiple values/objects and repeatedly run specific code blocks.  The basic loop types in Java are for, while and do while.  Branching Statements, which are used to alter the flow of control in loops
  • 5. There are three kinds of control structures: • Conditional Branches, which we use for choosing between two or more paths. There are three types in Java: if/else/else if, ternary operator and switch. • Loops that are used to iterate through multiple values/objects and repeatedly run specific code blocks. The basic loop types in Java are for, while and do while. • Branching Statements, which are used to alter the flow of control in loops. There are two types in Java: break and continue.
  • 6. 2. If/Else/Else If • The if/else statement is the most basic of control structure but can also be considered the very basis of decision making in programming. • While if can be used by itself, the most common use- scenario is choosing between two paths with if/else: if (count > 2) { System.out.println("Count is higher than 2"); } else { System.out.println("Count is lower or equal than 2"); }Theoretically, we can infinitely chain or nest if/else blocks but this will hurt code readability, and that's why it's not advised. • We'll explore alternative statements in the rest of this article.
  • 7. 3. Ternary Operator • We can use the ternary operator as a shorthand expression that works like an if/else statement. • Let's see our if/else example again: • if (count > 2) { System.out.println("Count is higher than 2"); } else { System.out.println("Count is lower or equal than 2"); }We can refactor this with a ternary as follows: • System.out.println(count > 2 ? "Count is higher than 2" : "Count is lower or equal than 2");While ternary can be a great way to make our code more readable, it isn't always a good substitute for if/else.
  • 8. 4.Switch • If we have multiple cases to choose from, we can use a switch statement. • Let's again see a simple example: • int count = 3; switch (count) { case 0: System.out.println("Count is equal to 0"); break; case 1: System.out.println("Count is equal to 1"); break; default: System.out.println("Count is either negative, or higher than 1"); break; }Three or more if/else statements can be hard to read. As one of the possible workarounds, we can use switch, as seen above.
  • 9. 5.Loops • We use loops when we need to repeat the same code multiple times in succession. • Let's see a quick example of comparable for and while type of loops: • for (int i = 1; i <= 50; i++) { methodToRepeat(); } int whileCounter = 1; while (whileCounter <= 50) { methodToRepeat(); whileCounter++; } Both code blocks above will call methodToRepeat 50 times.
  • 10. 6. Break • We need to use break to exit early from a loop. • Let's see a quick example: • List<String> names = getNameList(); String name = "John Doe"; int index = 0; for ( ; index < names.length; index++) { if (names[index].equals(name)) { break; } }Here, we are looking for a name in a list of names, and we want to stop looking once we've found it. • A loop would normally go to completion, but we've used break here to short-circuit that and exit early.
  • 11. 7. Continue • Simply put, continue means to skip the rest of the loop we're in: • List<String> names = getNameList(); String name = "John Doe"; String list = ""; for (int i = 0; i < names.length; i++) { if (names[i].equals(name)) { continue; } list += names[i]; }Here, we skip appending the duplicate names into the list.
  • 12. Different control structure:  The basic Control Structures in programming languages are: Conditionals (or Selection):  which are used to execute one or more statements if a condition is met. Loops (or Iteration):  which purpose is to repeat a statement a certain number of times or while a condition is fulfilled.
  • 13. Control statements in Java: • Decision Making Statements. • Simple if statement. • if-else statement. • Nested if statement. • Switch statement. • Looping statements. • While. • Do-while.