SlideShare a Scribd company logo
Control
structures
University of
Human Development
Contents
Comparison operators
Control structures
 if Statements
 For Statement
 switch Statement
 while & do loop
Comparison Operators
== Tests whether two values are equal
!= Tests whether two values are not equal
< Tests if left side value is less than to the right
side value
> Tests if left side value is greater than to the right
side value
<= Tests if left side value is less than or equal to the
right side value
>= Tests if left side value is greater than or equal to
the right side value
Operators
if Statements
Syntax :
(1)
he syntax of an if statement is
if (conditional clause)
{
Statement(s) block
}
 There are three basic forms for an if statement:
public class IT
{
public static void main(String args[])
{
int x = 10;
if ( x < 20 )
{
System.out.print("This is if statement");
}
}
}
Example
Result
Use when you want to do one thing or another thing
Syntax: (2)
if (conditional clause)
{
Statement(s) block
}
else
{
Statement(s) block
}
if. Else S…
public class IT
{
public static void main(String args[])
{
int x = 30;
if( x < 20 )
{
System.out.print("This is if statement");
}
else{
System.out.print("This is else statement");
}
}
}
Example
Result
if else if statement
Syntax
if (conditional clause) (3)
{
Statement(s) block
}
else if (conditional clause)
{
Statement(s) block
}
Use when there are three or more possibilities
if statement
User input
Example
Result
User is…
The for Loop :
A for loop is a repetition control
structure that allows you to efficiently
write a loop that needs to execute a
specific number of times.
A for loop is useful when you know how
many times a task is to be repeated.
Syntax :
The syntax of a for loop is:
for (initialization; Boolean_expression; update)
{
//Statements
}
The for Loop
Here is the flow of control in a for loop:
The initialization step is executed first, and
only once. This step allows you to
declare and initialize any loop control
variables. You are not required to put a
statement here, as long as a semicolon
appears.
Next, the Boolean expression is evaluated
The for Loop
If it is true, the body of the loop is
executed. If it is false, the body of the loop
does not execute and flow of control
jumps to the next statement past the for
loop.
After the body of the for loop executes, the
flow of control jumps back up to the
update statement
The for Loop
This statement allows you to update any
loop control
variables. This statement can be left blank,
as long as a semicolon appears after
the Boolean expression.
The Boolean expression is now evaluated
again. If it is true, the loop executes
and the process repeats itself (body of loop,
then update step, then Boolean
expression). After the Boolean expression is
false, the for loop terminates.
The for Loop
Example
public class IT
{
public static void main( String args[])
{
For ( int x = 10; x < 20; x = x+1)
{
System.out.print("value of x : " + x );
System.out.print("n");
}
}
}
This would produce the following result :
Result
Switch Statement
A switch statement allows a variable to be
tested for equality against a list of values.
Each value is called a case, and the
variable being switched on is checked for
each case.
Syntax :
The syntax of enhanced for loop is:
Switch (expression) {
case value :
//Statements
break; //optional
case value :
//Statements
break; //optional
//You can have any number of case statements.
default : //Optional
//Statements }
Switch Statement
 The following rules apply to a switch statement:
 The variable used in a switch statement can
only be a byte, short, int, or char.
 You can have any number of case statements
within a switch. Each case is followed by the
value to be compared to and a colon.
 The value for a case must be the same data
type as the variable in the switch and it must be
a constant or a literal.
Switch Statement
 When the variable being switched on is equal to a case, the
statements following that case will execute until a break
statement is reached.
 When a break statement is reached, the switch terminates,
and the flow of control jumps to the next line following the
switch statement.
 Not every case needs to contain a break. If no break
appears, the flow of control will fall through to subsequent
cases until a break is reached.
 A switch statement can have an optional default case,
which must appear at the end of the switch. The default
case can be used for performing a task when none of the
cases is true. No break is needed in the default case.
Switch Statement
Example:
Result
Compile and run above program using
various command line arguments.
This would produce the following result:
While loop :
While Loop Syntax
Do - While Loop
While Loop Syntax
While Loop
REFERENCES :
http://www.homeandlearn.co.uk/java/jav
a_if_else_statements.html
http://www.tutorialspoint.com/java/java_
decision_making.htm
file:///C:/Users/DotNet/Downloads/files-
2._Lectures_8-Do_While_Loop.pdf
End

More Related Content

What's hot

Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
Hossain Md Shakhawat
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
Sonya Akter Rupa
 
The Switch Statement in java
The Switch Statement in javaThe Switch Statement in java
The Switch Statement in java
Talha Saleem
 
Control statements in java programmng
Control statements in java programmngControl statements in java programmng
Control statements in java programmng
Savitribai Phule Pune University
 
Switch statements in Java
Switch statements  in JavaSwitch statements  in Java
Switch statements in Java
Jin Castor
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)
Way2itech
 
Selection statements
Selection statementsSelection statements
Selection statements
Harsh Dabas
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statements
jyoti_lakhani
 
LOOPS AND DECISIONS
LOOPS AND DECISIONSLOOPS AND DECISIONS
LOOPS AND DECISIONS
Aami Kakakhel
 
Control structures i
Control structures i Control structures i
Control structures i
Ahmad Idrees
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
Raj Parekh
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
Madishetty Prathibha
 
Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statements
Future Programming
 
Selection structure
Selection structureSelection structure
Selection structure
Jyoti Pokharna
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
Kuppusamy P
 
Presentation on C Switch Case Statements
Presentation on C Switch Case StatementsPresentation on C Switch Case Statements
Presentation on C Switch Case Statements
Dipesh Pandey
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
Jyoti Bhardwaj
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
baabtra.com - No. 1 supplier of quality freshers
 
Control statement in c
Control statement in cControl statement in c

What's hot (20)

Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
 
The Switch Statement in java
The Switch Statement in javaThe Switch Statement in java
The Switch Statement in java
 
Control statements in java programmng
Control statements in java programmngControl statements in java programmng
Control statements in java programmng
 
Switch statements in Java
Switch statements  in JavaSwitch statements  in Java
Switch statements in Java
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)
 
Selection statements
Selection statementsSelection statements
Selection statements
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statements
 
LOOPS AND DECISIONS
LOOPS AND DECISIONSLOOPS AND DECISIONS
LOOPS AND DECISIONS
 
Control structures i
Control structures i Control structures i
Control structures i
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
10. switch case
10. switch case10. switch case
10. switch case
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statements
 
Selection structure
Selection structureSelection structure
Selection structure
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Presentation on C Switch Case Statements
Presentation on C Switch Case StatementsPresentation on C Switch Case Statements
Presentation on C Switch Case Statements
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 
Control statement in c
Control statement in cControl statement in c
Control statement in c
 

Viewers also liked

NEWS HEADLINES June 3, 2014
NEWS HEADLINES June 3, 2014NEWS HEADLINES June 3, 2014
NEWS HEADLINES June 3, 2014
Headlines.am
 
About dexcs2014of
About dexcs2014ofAbout dexcs2014of
About dexcs2014of
Etsuji Nomura
 
готовій план наркопоста.Docке
готовій план наркопоста.Docкеготовій план наркопоста.Docке
готовій план наркопоста.Docке
Сергій Якуба
 
Матеріали до йроку 18 з всесвітньої історії 7-клас
Матеріали до йроку 18 з всесвітньої історії 7-класМатеріали до йроку 18 з всесвітньої історії 7-клас
Матеріали до йроку 18 з всесвітньої історії 7-клас
Надежда Бедикян
 
HONG KONG NEWS - OCTOBER 9, 2014
HONG KONG NEWS - OCTOBER 9, 2014HONG KONG NEWS - OCTOBER 9, 2014
HONG KONG NEWS - OCTOBER 9, 2014
Headlines.am
 
Formative Feedback Harper Adams LT Forum
Formative Feedback Harper Adams LT ForumFormative Feedback Harper Adams LT Forum
Formative Feedback Harper Adams LT Forum
Rachel Forsyth
 
тиждень безпеки життєдіяльності
тиждень безпеки життєдіяльностітиждень безпеки життєдіяльності
тиждень безпеки життєдіяльності
Сергій Якуба
 
щодо запобігання бездоглядності
щодо запобігання бездоглядностіщодо запобігання бездоглядності
щодо запобігання бездоглядності
Сергій Якуба
 
Webinar 02 2015
Webinar 02 2015Webinar 02 2015
Webinar 02 2015
Rachel Forsyth
 
день учителя 2014
день учителя 2014день учителя 2014
день учителя 2014
Сергій Якуба
 
профілактика шкідливих звичок
профілактика шкідливих звичокпрофілактика шкідливих звичок
профілактика шкідливих звичок
Сергій Якуба
 
Moxon Huddersfield interview questions and answers
Moxon Huddersfield interview questions and answersMoxon Huddersfield interview questions and answers
Moxon Huddersfield interview questions and answers
rlykimbe
 
HEIR conference 8-9 September 2014: Forsyth and Stubbs
HEIR conference 8-9 September 2014: Forsyth and StubbsHEIR conference 8-9 September 2014: Forsyth and Stubbs
HEIR conference 8-9 September 2014: Forsyth and Stubbs
Rachel Forsyth
 
дніпропетровщина моя рідна земля
дніпропетровщина моя рідна землядніпропетровщина моя рідна земля
дніпропетровщина моя рідна земля
Сергій Якуба
 

Viewers also liked (15)

NEWS HEADLINES June 3, 2014
NEWS HEADLINES June 3, 2014NEWS HEADLINES June 3, 2014
NEWS HEADLINES June 3, 2014
 
About dexcs2014of
About dexcs2014ofAbout dexcs2014of
About dexcs2014of
 
готовій план наркопоста.Docке
готовій план наркопоста.Docкеготовій план наркопоста.Docке
готовій план наркопоста.Docке
 
Inf tema 2_urok12_6_klas
Inf tema 2_urok12_6_klasInf tema 2_urok12_6_klas
Inf tema 2_urok12_6_klas
 
Матеріали до йроку 18 з всесвітньої історії 7-клас
Матеріали до йроку 18 з всесвітньої історії 7-класМатеріали до йроку 18 з всесвітньої історії 7-клас
Матеріали до йроку 18 з всесвітньої історії 7-клас
 
HONG KONG NEWS - OCTOBER 9, 2014
HONG KONG NEWS - OCTOBER 9, 2014HONG KONG NEWS - OCTOBER 9, 2014
HONG KONG NEWS - OCTOBER 9, 2014
 
Formative Feedback Harper Adams LT Forum
Formative Feedback Harper Adams LT ForumFormative Feedback Harper Adams LT Forum
Formative Feedback Harper Adams LT Forum
 
тиждень безпеки життєдіяльності
тиждень безпеки життєдіяльностітиждень безпеки життєдіяльності
тиждень безпеки життєдіяльності
 
щодо запобігання бездоглядності
щодо запобігання бездоглядностіщодо запобігання бездоглядності
щодо запобігання бездоглядності
 
Webinar 02 2015
Webinar 02 2015Webinar 02 2015
Webinar 02 2015
 
день учителя 2014
день учителя 2014день учителя 2014
день учителя 2014
 
профілактика шкідливих звичок
профілактика шкідливих звичокпрофілактика шкідливих звичок
профілактика шкідливих звичок
 
Moxon Huddersfield interview questions and answers
Moxon Huddersfield interview questions and answersMoxon Huddersfield interview questions and answers
Moxon Huddersfield interview questions and answers
 
HEIR conference 8-9 September 2014: Forsyth and Stubbs
HEIR conference 8-9 September 2014: Forsyth and StubbsHEIR conference 8-9 September 2014: Forsyth and Stubbs
HEIR conference 8-9 September 2014: Forsyth and Stubbs
 
дніпропетровщина моя рідна земля
дніпропетровщина моя рідна землядніпропетровщина моя рідна земля
дніпропетровщина моя рідна земля
 

Similar to Control structures

Control Structures Python like conditions and loops
Control Structures Python like conditions and loopsControl Structures Python like conditions and loops
Control Structures Python like conditions and loops
ramireddyobulakondar
 
Control statements
Control statementsControl statements
Control statements
CutyChhaya
 
Switch Case in C Program
Switch Case in C ProgramSwitch Case in C Program
Switch Case in C Program
Rup Chowdhury
 
Java loops
Java loopsJava loops
Java loops
ricardovigan
 
Chapter 5 java
Chapter 5 javaChapter 5 java
Chapter 5 java
Ahmad sohail Kakar
 
06-Control-Statementskkkkkkkkkkkkkk.pptx
06-Control-Statementskkkkkkkkkkkkkk.pptx06-Control-Statementskkkkkkkkkkkkkk.pptx
06-Control-Statementskkkkkkkkkkkkkk.pptx
kamalsmail1
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
TejaswiB4
 
Conditional Statement-pptx-lesson3asdfsa
Conditional Statement-pptx-lesson3asdfsaConditional Statement-pptx-lesson3asdfsa
Conditional Statement-pptx-lesson3asdfsa
MariNel48
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
Anil Dutt
 
Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7
MLG College of Learning, Inc
 
Computer programming 2 Lesson 9
Computer programming 2  Lesson 9Computer programming 2  Lesson 9
Computer programming 2 Lesson 9
MLG College of Learning, Inc
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
Ujwala Junghare
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
TANUJ ⠀
 
07 flow control
07   flow control07   flow control
07 flow control
dhrubo kayal
 
Flow of control
Flow of controlFlow of control
Flow of control
Shobhit Singhal
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
Niket Chandrawanshi
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
MURALIDHAR R
 
Python session3
Python session3Python session3
Python session3
Aswin Krishnamoorthy
 
Chapter 2 - Flow of Control Part I.pdf
Chapter 2 -  Flow of Control Part I.pdfChapter 2 -  Flow of Control Part I.pdf
Chapter 2 - Flow of Control Part I.pdf
KirubelWondwoson1
 

Similar to Control structures (20)

Control Structures Python like conditions and loops
Control Structures Python like conditions and loopsControl Structures Python like conditions and loops
Control Structures Python like conditions and loops
 
Control statements
Control statementsControl statements
Control statements
 
Switch Case in C Program
Switch Case in C ProgramSwitch Case in C Program
Switch Case in C Program
 
Java loops
Java loopsJava loops
Java loops
 
Chapter 5 java
Chapter 5 javaChapter 5 java
Chapter 5 java
 
06-Control-Statementskkkkkkkkkkkkkk.pptx
06-Control-Statementskkkkkkkkkkkkkk.pptx06-Control-Statementskkkkkkkkkkkkkk.pptx
06-Control-Statementskkkkkkkkkkkkkk.pptx
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 
Conditional Statement-pptx-lesson3asdfsa
Conditional Statement-pptx-lesson3asdfsaConditional Statement-pptx-lesson3asdfsa
Conditional Statement-pptx-lesson3asdfsa
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7
 
Computer programming 2 Lesson 9
Computer programming 2  Lesson 9Computer programming 2  Lesson 9
Computer programming 2 Lesson 9
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
07 flow control
07   flow control07   flow control
07 flow control
 
Flow of control
Flow of controlFlow of control
Flow of control
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
Python session3
Python session3Python session3
Python session3
 
Chapter 2 - Flow of Control Part I.pdf
Chapter 2 -  Flow of Control Part I.pdfChapter 2 -  Flow of Control Part I.pdf
Chapter 2 - Flow of Control Part I.pdf
 

Recently uploaded

Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
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
 
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
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
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
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
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
 
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.
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 

Recently uploaded (20)

Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
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
 
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
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
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
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
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
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 

Control structures

  • 2. Contents Comparison operators Control structures  if Statements  For Statement  switch Statement  while & do loop
  • 3. Comparison Operators == Tests whether two values are equal != Tests whether two values are not equal < Tests if left side value is less than to the right side value > Tests if left side value is greater than to the right side value <= Tests if left side value is less than or equal to the right side value >= Tests if left side value is greater than or equal to the right side value Operators
  • 4. if Statements Syntax : (1) he syntax of an if statement is if (conditional clause) { Statement(s) block }  There are three basic forms for an if statement:
  • 5. public class IT { public static void main(String args[]) { int x = 10; if ( x < 20 ) { System.out.print("This is if statement"); } } } Example
  • 7. Use when you want to do one thing or another thing Syntax: (2) if (conditional clause) { Statement(s) block } else { Statement(s) block } if. Else S…
  • 8. public class IT { public static void main(String args[]) { int x = 30; if( x < 20 ) { System.out.print("This is if statement"); } else{ System.out.print("This is else statement"); } } } Example
  • 10. if else if statement Syntax if (conditional clause) (3) { Statement(s) block } else if (conditional clause) { Statement(s) block } Use when there are three or more possibilities if statement
  • 13. The for Loop : A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. A for loop is useful when you know how many times a task is to be repeated.
  • 14. Syntax : The syntax of a for loop is: for (initialization; Boolean_expression; update) { //Statements } The for Loop
  • 15. Here is the flow of control in a for loop: The initialization step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears. Next, the Boolean expression is evaluated The for Loop
  • 16. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and flow of control jumps to the next statement past the for loop. After the body of the for loop executes, the flow of control jumps back up to the update statement The for Loop
  • 17. This statement allows you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the Boolean expression. The Boolean expression is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then update step, then Boolean expression). After the Boolean expression is false, the for loop terminates. The for Loop
  • 18. Example public class IT { public static void main( String args[]) { For ( int x = 10; x < 20; x = x+1) { System.out.print("value of x : " + x ); System.out.print("n"); } } }
  • 19. This would produce the following result : Result
  • 20. Switch Statement A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.
  • 21. Syntax : The syntax of enhanced for loop is: Switch (expression) { case value : //Statements break; //optional case value : //Statements break; //optional //You can have any number of case statements. default : //Optional //Statements } Switch Statement
  • 22.  The following rules apply to a switch statement:  The variable used in a switch statement can only be a byte, short, int, or char.  You can have any number of case statements within a switch. Each case is followed by the value to be compared to and a colon.  The value for a case must be the same data type as the variable in the switch and it must be a constant or a literal. Switch Statement
  • 23.  When the variable being switched on is equal to a case, the statements following that case will execute until a break statement is reached.  When a break statement is reached, the switch terminates, and the flow of control jumps to the next line following the switch statement.  Not every case needs to contain a break. If no break appears, the flow of control will fall through to subsequent cases until a break is reached.  A switch statement can have an optional default case, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case. Switch Statement
  • 25. Result Compile and run above program using various command line arguments. This would produce the following result:
  • 28. Do - While Loop
  • 31. End