SlideShare a Scribd company logo
1 of 18
STATEMENT LEVEL CONTROL STRUCTURES
1.Introduction
2. Compound Statements
3.Selection Statements
4.Iterative Statements
5.Unconditional Branching
INTRODUCTION
Selection, unconditional branching and Iterative
statements are a control structure. These control
structure are control statement.
Control Statements are select and repeat control
flow whereas statements in FORRTRAN I were based
directly on IBM 704 Hardware.
The IBM 704 ,introduced by IBM in 1954,was the
first mass-produced computer with floating-point
arithmetic hardware and it is the manual of
operation states. The type 704 Electronic Data-
processing Machine is a large-scale, high-speed
electronic calculator controlled by an internally
CONTROL STRUCTURE
Design question should a control structure have multiple entries?
Structure programming:
 structure of the program text should be help us for undersetting
what the program does?
Flow chart control into the program as a result we can find out
syntactic structure of the program text like single entry or exit
SECTION STATEMENTS
A Section statements provides that means of choosing between two or
more paths of execution.
Two way selectors
General form:
If control expression(condition)
Then clause
Else clause
ALGOL 60:
If (Boolean expr)
Then statement(then clause)
Else statement(then clause)
NOTE: the statement could be single or compound
SELECTORS OF NESTING
Which if gets the else?
Static semantics rule in java, c , c++ and c# else matches with nearest if.
Example of java:
If (sum == 0)
If (count == 0)
Result = 0;
Else result = 1;
To force an alternative semantics, compound statements may be used like
If (sum == 0) {
If (count == 0)
Result = 0; }
Else result = 1;
NOTE: every requires that all then and else clauses to be compound.
SELECTION STATEMENT:MULTIPLE WAY
Allow selection of one of any number with statement or group statement like switch statement
Switch (expression){
Case const_expr_1: statement 1;
Case const_expr_2: statement 2;
-----------
Case const_expr_n: statement n;{Default:statement n+1]
}
Example:
Switch(rana){
Case 1:
Case2:odd+= 1; sumodd +=rana; break;
Case2:even+=1;sumeven +=rana;break; }
MULTIPLE WAY SECTION FOR IF STATEMENT
Multiple way can be appear two way sector from direct extension like if and
else in the following way:
If…………………
then……………………..
Elseif………..
then…………………..
Elseif………………
Then…………………………
Else……….
End if
ITERATIVE STATEMENTS
The repeated execution of a statement or compound statement is accomplished either by iterative and
the general statement are(A)Where is the control mechanism in the loop.(B)How is iteration controlled?
Object iteration of Php: PHP 5 provides a way for objects to be defined. so it is possible to iterate
through a list of items. for example a foreach statement.
<?php
class MyClass{
public $var1 = 'value 1';
public $var2 = 'value 2';
public $var3 = 'value 3';
protected $protected = 'protected var';
private $private = 'private var';
function iterateVisible() {
print "MyClass::iterateVisible:n";
foreach ($this as $key => $value) {
print "$key => $valuen"; } }}
$class = new MyClass();
foreach($class as $key => $value) {
print "$key => $valuen";}
print "n";
$class->iterateVisible();
OUTPUT OF ITERATIVE STATEMENTS: EXAMPLE
var1 => value 1
var2 => value 2
var3 => value 3
MyClass::iterateVisible:
var1 => value 1
var2 => value 2
var3 => value 3
protected => protected var
private => private var
OBJECT ITERATION OF C
For statement:
For (expression1;expression2;expressions)
Statement;(1=initialises; 2 =terminate test; 3= modifier )
For example:
Int x;
Main() {
For (x=3;x>0;x--){
Printf(“x=%d n”,x);
}}
Out put 321
COUNTER CONTROLLED LOOPS: C++
C++ differs from c in two ways:
1.the control expression can be Boolean.
2.the initial expression can include variable definitions.
Example:
for (int count = 1;count <=10;count++)
{…}
Java and c#
Differs from c++ in that the control expression must be Boolean.
LOGICALLY CONTROLLED LOOPS: PASCAL
Pascal has separate pre-test and post-test logical loop statements(while do
and repeat until)
Example of remove adjacent duplicates:1,1,2,2,2,3,1,4,4 ->1,2 3,1,4
Program uniq(input outpot);
Var x,next : integer;
Begin Read(x);
While x<>0 do begin
WriteIn(x);
Repeat read (next);until next<>x;
X:= next;
End;
UNCONDITIONAL BRANCHING
Well known mechanism: go to statement.
Major concern: readability
Transfers execution control to a specified place in the program
Some languages do not support go to statement(java )
C# offers go to statement(can be used in switch statements)
SYNTAX OF STATEMENTS‘:C
S :: = ;
E;
{ Slist }
if ( E ) S
if ( E ) S else S
while ( E ) S
do S while ( E ) ;
for ( Eopt ; Eopt; Eopt ) S
switch ( E ) S
Case Constant : S
SYNTAX OF STATEMENTS:C
default : S
break ;
continue ;
return ;
return E ;
goto L ;
L : S
Slist :: = ( empty )
Slist S
Eopt ::= ( empty )
E
PRECONDITION AND POST
CONDITION
A Post conditions are sometimes tested using assertions within the code itself. however post conditions
are simply included in the documentation of the affected section of code.
PROGRAM PROOF PROCESS
A weakest precondition is the least restrictive precondition that will
guarantee the postcondition.
For example: -a = b+1{a>1}
-one possible precondition: {b>10}
-weakest precondition :{b >0}
The post condition for the entire program is the desired result
work back through the program to the first statement. If the
precondition on the first statement is the same as the program
specification, the program is correct
END OF THE PRESENTATION

More Related Content

What's hot

Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...Jay Baxi
 
Fortran - concise review
Fortran - concise reviewFortran - concise review
Fortran - concise reviewHans Zimermann
 
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - BasicsNotes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - BasicsJay Baxi
 
Notes: Verilog Part 4- Behavioural Modelling
Notes: Verilog Part 4- Behavioural ModellingNotes: Verilog Part 4- Behavioural Modelling
Notes: Verilog Part 4- Behavioural ModellingJay Baxi
 
Storage classes arrays & functions in C Language
Storage classes arrays & functions in C LanguageStorage classes arrays & functions in C Language
Storage classes arrays & functions in C LanguageJenish Bhavsar
 

What's hot (20)

Intr fortran90
Intr fortran90Intr fortran90
Intr fortran90
 
Fortran 95
Fortran 95Fortran 95
Fortran 95
 
C programming part4
C programming part4C programming part4
C programming part4
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
C programming session3
C programming  session3C programming  session3
C programming session3
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
 
C programming session6
C programming  session6C programming  session6
C programming session6
 
Fortran - concise review
Fortran - concise reviewFortran - concise review
Fortran - concise review
 
Ch3 selection
Ch3 selectionCh3 selection
Ch3 selection
 
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - BasicsNotes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
 
Notes: Verilog Part 4- Behavioural Modelling
Notes: Verilog Part 4- Behavioural ModellingNotes: Verilog Part 4- Behavioural Modelling
Notes: Verilog Part 4- Behavioural Modelling
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
Storage classes arrays & functions in C Language
Storage classes arrays & functions in C LanguageStorage classes arrays & functions in C Language
Storage classes arrays & functions in C Language
 
C programming part2
C programming part2C programming part2
C programming part2
 
Unit3 cspc
Unit3 cspcUnit3 cspc
Unit3 cspc
 
C++ rajan
C++ rajanC++ rajan
C++ rajan
 
Ch4 Expressions
Ch4 ExpressionsCh4 Expressions
Ch4 Expressions
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 

Viewers also liked

69 goracych zabaw dla par - ebook
69 goracych zabaw dla par - ebook69 goracych zabaw dla par - ebook
69 goracych zabaw dla par - ebooke-booksweb.pl
 
Categorical propositions
Categorical propositions Categorical propositions
Categorical propositions anandhjose
 
LOGIC AND CRITICAL THINKING
LOGIC AND CRITICAL THINKINGLOGIC AND CRITICAL THINKING
LOGIC AND CRITICAL THINKINGtagupaleomark
 
Chapter 1 Logic of Compound Statements
Chapter 1 Logic of Compound StatementsChapter 1 Logic of Compound Statements
Chapter 1 Logic of Compound Statementsguestd166eb5
 
Discrete Mathematics - Propositional Logic
Discrete Mathematics - Propositional LogicDiscrete Mathematics - Propositional Logic
Discrete Mathematics - Propositional LogicUniversity of Potsdam
 
Judgment and proposition or logical statement
Judgment and proposition or logical statementJudgment and proposition or logical statement
Judgment and proposition or logical statementling selanoba
 
Articles, indefinite and definite
Articles, indefinite and definiteArticles, indefinite and definite
Articles, indefinite and definiteIngles Corporativo
 
Unit 3 - Reference and Sense
Unit 3 -  Reference and SenseUnit 3 -  Reference and Sense
Unit 3 - Reference and SenseAshwag Al Hamid
 
Service Desk Proposition Presentation
Service Desk Proposition PresentationService Desk Proposition Presentation
Service Desk Proposition PresentationSimonAnthony
 
CATEGORICAL SYLLOGISM
CATEGORICAL SYLLOGISMCATEGORICAL SYLLOGISM
CATEGORICAL SYLLOGISMashelle14
 
Definite and indefinite articles
Definite and indefinite articlesDefinite and indefinite articles
Definite and indefinite articlesAgita Ozolina
 
Unit 2: Sentences, Utterances, and Propositions
Unit 2: Sentences, Utterances, and PropositionsUnit 2: Sentences, Utterances, and Propositions
Unit 2: Sentences, Utterances, and PropositionsAshwag Al Hamid
 

Viewers also liked (20)

69 goracych zabaw dla par - ebook
69 goracych zabaw dla par - ebook69 goracych zabaw dla par - ebook
69 goracych zabaw dla par - ebook
 
Inversion
InversionInversion
Inversion
 
Logic
LogicLogic
Logic
 
Chapter 06 hurley 12e
Chapter 06 hurley 12eChapter 06 hurley 12e
Chapter 06 hurley 12e
 
Logic hand outs#4
Logic hand outs#4Logic hand outs#4
Logic hand outs#4
 
Categorical propositions
Categorical propositions Categorical propositions
Categorical propositions
 
LOGIC AND CRITICAL THINKING
LOGIC AND CRITICAL THINKINGLOGIC AND CRITICAL THINKING
LOGIC AND CRITICAL THINKING
 
Hum 200 w7
Hum 200 w7 Hum 200 w7
Hum 200 w7
 
Chapter 1 Logic of Compound Statements
Chapter 1 Logic of Compound StatementsChapter 1 Logic of Compound Statements
Chapter 1 Logic of Compound Statements
 
Discrete Mathematics - Propositional Logic
Discrete Mathematics - Propositional LogicDiscrete Mathematics - Propositional Logic
Discrete Mathematics - Propositional Logic
 
judgment(proposition)
judgment(proposition)judgment(proposition)
judgment(proposition)
 
Judgment and proposition or logical statement
Judgment and proposition or logical statementJudgment and proposition or logical statement
Judgment and proposition or logical statement
 
Articles, indefinite and definite
Articles, indefinite and definiteArticles, indefinite and definite
Articles, indefinite and definite
 
Unit 3 - Reference and Sense
Unit 3 -  Reference and SenseUnit 3 -  Reference and Sense
Unit 3 - Reference and Sense
 
Logic
LogicLogic
Logic
 
Service Desk Proposition Presentation
Service Desk Proposition PresentationService Desk Proposition Presentation
Service Desk Proposition Presentation
 
CATEGORICAL SYLLOGISM
CATEGORICAL SYLLOGISMCATEGORICAL SYLLOGISM
CATEGORICAL SYLLOGISM
 
Definite and indefinite articles
Definite and indefinite articlesDefinite and indefinite articles
Definite and indefinite articles
 
Logic Ppt
Logic PptLogic Ppt
Logic Ppt
 
Unit 2: Sentences, Utterances, and Propositions
Unit 2: Sentences, Utterances, and PropositionsUnit 2: Sentences, Utterances, and Propositions
Unit 2: Sentences, Utterances, and Propositions
 

Similar to PM1

Control structures ii
Control structures ii Control structures ii
Control structures ii Ahmad Idrees
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlENGWAU TONNY
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.pptManojKhadilkar1
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming languageVasavi College of Engg
 
Control statements
Control statementsControl statements
Control statementsCutyChhaya
 
Btech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsBtech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsRai University
 
Mca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsMca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsRai University
 
handling input output and control statements
 handling input output and control statements handling input output and control statements
handling input output and control statementsRai University
 
Diploma ii cfpc u-3 handling input output and control statements
Diploma ii  cfpc u-3 handling input output and control statementsDiploma ii  cfpc u-3 handling input output and control statements
Diploma ii cfpc u-3 handling input output and control statementsRai University
 
C++ decision making
C++ decision makingC++ decision making
C++ decision makingZohaib Ahmed
 
control statements
control statementscontrol statements
control statementsAzeem Sultan
 

Similar to PM1 (20)

C++ chapter 4
C++ chapter 4C++ chapter 4
C++ chapter 4
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
 
Comp ppt (1)
Comp ppt (1)Comp ppt (1)
Comp ppt (1)
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Chap05
Chap05Chap05
Chap05
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Control statements
Control statementsControl statements
Control statements
 
Btech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsBtech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statements
 
Mca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsMca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statements
 
handling input output and control statements
 handling input output and control statements handling input output and control statements
handling input output and control statements
 
Session 3
Session 3Session 3
Session 3
 
Diploma ii cfpc u-3 handling input output and control statements
Diploma ii  cfpc u-3 handling input output and control statementsDiploma ii  cfpc u-3 handling input output and control statements
Diploma ii cfpc u-3 handling input output and control statements
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
control statements
control statementscontrol statements
control statements
 

More from ra na

Project
Project Project
Project ra na
 
Networking
NetworkingNetworking
Networkingra na
 
computer website
computer websitecomputer website
computer websitera na
 
hajer
hajerhajer
hajerra na
 
PM3 ARTICALS
PM3 ARTICALSPM3 ARTICALS
PM3 ARTICALSra na
 
PM2 ARTICALS
PM2 ARTICALSPM2 ARTICALS
PM2 ARTICALSra na
 
Assignment of database
Assignment of databaseAssignment of database
Assignment of databasera na
 

More from ra na (9)

Project
Project Project
Project
 
Networking
NetworkingNetworking
Networking
 
computer website
computer websitecomputer website
computer website
 
hajer
hajerhajer
hajer
 
PM3 ARTICALS
PM3 ARTICALSPM3 ARTICALS
PM3 ARTICALS
 
PM2 ARTICALS
PM2 ARTICALSPM2 ARTICALS
PM2 ARTICALS
 
PM3
PM3PM3
PM3
 
PM2
PM2PM2
PM2
 
Assignment of database
Assignment of databaseAssignment of database
Assignment of database
 

PM1

  • 1. STATEMENT LEVEL CONTROL STRUCTURES 1.Introduction 2. Compound Statements 3.Selection Statements 4.Iterative Statements 5.Unconditional Branching
  • 2. INTRODUCTION Selection, unconditional branching and Iterative statements are a control structure. These control structure are control statement. Control Statements are select and repeat control flow whereas statements in FORRTRAN I were based directly on IBM 704 Hardware. The IBM 704 ,introduced by IBM in 1954,was the first mass-produced computer with floating-point arithmetic hardware and it is the manual of operation states. The type 704 Electronic Data- processing Machine is a large-scale, high-speed electronic calculator controlled by an internally
  • 3. CONTROL STRUCTURE Design question should a control structure have multiple entries? Structure programming:  structure of the program text should be help us for undersetting what the program does? Flow chart control into the program as a result we can find out syntactic structure of the program text like single entry or exit
  • 4. SECTION STATEMENTS A Section statements provides that means of choosing between two or more paths of execution. Two way selectors General form: If control expression(condition) Then clause Else clause ALGOL 60: If (Boolean expr) Then statement(then clause) Else statement(then clause) NOTE: the statement could be single or compound
  • 5. SELECTORS OF NESTING Which if gets the else? Static semantics rule in java, c , c++ and c# else matches with nearest if. Example of java: If (sum == 0) If (count == 0) Result = 0; Else result = 1; To force an alternative semantics, compound statements may be used like If (sum == 0) { If (count == 0) Result = 0; } Else result = 1; NOTE: every requires that all then and else clauses to be compound.
  • 6. SELECTION STATEMENT:MULTIPLE WAY Allow selection of one of any number with statement or group statement like switch statement Switch (expression){ Case const_expr_1: statement 1; Case const_expr_2: statement 2; ----------- Case const_expr_n: statement n;{Default:statement n+1] } Example: Switch(rana){ Case 1: Case2:odd+= 1; sumodd +=rana; break; Case2:even+=1;sumeven +=rana;break; }
  • 7. MULTIPLE WAY SECTION FOR IF STATEMENT Multiple way can be appear two way sector from direct extension like if and else in the following way: If………………… then…………………….. Elseif……….. then………………….. Elseif……………… Then………………………… Else………. End if
  • 8. ITERATIVE STATEMENTS The repeated execution of a statement or compound statement is accomplished either by iterative and the general statement are(A)Where is the control mechanism in the loop.(B)How is iteration controlled? Object iteration of Php: PHP 5 provides a way for objects to be defined. so it is possible to iterate through a list of items. for example a foreach statement. <?php class MyClass{ public $var1 = 'value 1'; public $var2 = 'value 2'; public $var3 = 'value 3'; protected $protected = 'protected var'; private $private = 'private var'; function iterateVisible() { print "MyClass::iterateVisible:n"; foreach ($this as $key => $value) { print "$key => $valuen"; } }} $class = new MyClass(); foreach($class as $key => $value) { print "$key => $valuen";} print "n"; $class->iterateVisible();
  • 9. OUTPUT OF ITERATIVE STATEMENTS: EXAMPLE var1 => value 1 var2 => value 2 var3 => value 3 MyClass::iterateVisible: var1 => value 1 var2 => value 2 var3 => value 3 protected => protected var private => private var
  • 10. OBJECT ITERATION OF C For statement: For (expression1;expression2;expressions) Statement;(1=initialises; 2 =terminate test; 3= modifier ) For example: Int x; Main() { For (x=3;x>0;x--){ Printf(“x=%d n”,x); }} Out put 321
  • 11. COUNTER CONTROLLED LOOPS: C++ C++ differs from c in two ways: 1.the control expression can be Boolean. 2.the initial expression can include variable definitions. Example: for (int count = 1;count <=10;count++) {…} Java and c# Differs from c++ in that the control expression must be Boolean.
  • 12. LOGICALLY CONTROLLED LOOPS: PASCAL Pascal has separate pre-test and post-test logical loop statements(while do and repeat until) Example of remove adjacent duplicates:1,1,2,2,2,3,1,4,4 ->1,2 3,1,4 Program uniq(input outpot); Var x,next : integer; Begin Read(x); While x<>0 do begin WriteIn(x); Repeat read (next);until next<>x; X:= next; End;
  • 13. UNCONDITIONAL BRANCHING Well known mechanism: go to statement. Major concern: readability Transfers execution control to a specified place in the program Some languages do not support go to statement(java ) C# offers go to statement(can be used in switch statements)
  • 14. SYNTAX OF STATEMENTS‘:C S :: = ; E; { Slist } if ( E ) S if ( E ) S else S while ( E ) S do S while ( E ) ; for ( Eopt ; Eopt; Eopt ) S switch ( E ) S Case Constant : S
  • 15. SYNTAX OF STATEMENTS:C default : S break ; continue ; return ; return E ; goto L ; L : S Slist :: = ( empty ) Slist S Eopt ::= ( empty ) E
  • 16. PRECONDITION AND POST CONDITION A Post conditions are sometimes tested using assertions within the code itself. however post conditions are simply included in the documentation of the affected section of code.
  • 17. PROGRAM PROOF PROCESS A weakest precondition is the least restrictive precondition that will guarantee the postcondition. For example: -a = b+1{a>1} -one possible precondition: {b>10} -weakest precondition :{b >0} The post condition for the entire program is the desired result work back through the program to the first statement. If the precondition on the first statement is the same as the program specification, the program is correct
  • 18. END OF THE PRESENTATION