SlideShare a Scribd company logo
1 of 25
The IF Statement
 Use the IF statement to control if a part of the program
executes. If the condition is TRUE, one set of one or
more statement executes; and if the condition is
FALSE, another set of one or more statements executes
 IF <Boolean expression> THEN <statement>
 IF Amount < 0 THEN
Amount := -Amount;
IF - THEN - ELSE
 IF <Boolean expression> THEN
<statement 1>
ELSE
<statement 2>
IF Quantity <> 0 THEN
UnitPrice := TotalPrice / Quantity
ELSE
UnitPrice := 0;
;
The EXIT Statement
 Code in a trigger executes sequentially from the top to
the bottom
 IF Quantity = 0 THEN
EXIT;
UnitPrice := TotalPrice / Quantity;
Code Indentation
 To indent several lines of code, select the lines, and
then press TAB.
 To indent several lines of code to the left, select those
lines, and press SHIFT+TAB
The CASE Statement
 Use the CASE conditional statement when there are
more than two possible values for the condition.
 CASE <expression> OF
<value set 1> : <statement 1>;
<value set 2> : <statement 2>;
<value set n> : <statement n>;
[ELSE <statement n+1>]
END
CASE Example
Number:=25;
CASE Number OF
1,2,9: MESSAGE('1, 2, or 9.');
10..100: MESSAGE('In the range from 10 to 100.');
ELSE
MESSAGE('Neither 1, 2, 9, nor in the range from 10 to 100.');
END;
Output: In the range from 10 to 100
Compound Statements and Comments
 A compound statement is multiple statements
 A comment is a description that developers write in
their code .
 // this code comment
 {
line 1
line 2
line 3
}
The Syntax of Compound Statements
 BEGIN <statement> {; <statement>} END
 IF Quantity <> 0 THEN
BEGIN
UnitPrice := ExtendedPrice / Quantity;
TotalPrice := TotalPrice + ExtendedPrice;
END;
IF Quantity <> 0 THEN
BEGIN
UnitPrice := ExtendedPrice / Quantity;
TotalPrice := TotalPrice + ExtendedPrice;
END //No ;
ELSE
BEGIN
UnitPrice := 0;
EXIT;
END; // ;
Compound Statement by Using Nested IF Statements
IF Amount <> 0 THEN
IF Amount > 0 THEN
Sales := Sales + Amount
ELSE
IF Reason = Reason::Return THEN
IF ReasonForReturn = ReasonForReturn::Defective THEN
Refund := Refund + Amount
ELSE
Credits := Credits + Amount
ELSE
Sales := Sales - Amount;
To have organized code
 Use correct indentation.
 Use meaningful variable names
 Do not use negative variable names (for example,
DoNotDelete
 Use Booleans to designate Yes or No choices.
Demonstrations
 Demonstration: Use the Conditional and Compound
Statements in a Page (Page 12)
 Practice: Nested IF (Page 21)
 Lab 6.1: Use Conditional and Compound Statements
(Page 23)
Arrays
 Arrays are complex variables that contain a group of
variables with the same data type.
 Simple data types only have a single value.
 A complex data type has multiple values.
 Number array with 10 elements
10 5 4 50 21 63 20 12 42 25
Form 223
How to clear Variable
 CLEAR(<variable>);
 For example, for a one-dimensional array named
SaleAmount of type Decimal, use the following
function call to set all elements in SaleAmount to zero
 CLEAR(SaleAmount);
Array Element Syntax
 <identifier>[<index expression>{,<index expression>}]
 Box[5] := 25;
ARRAYLEN Function
 In your array you have seven elements but you are
trying to access 8th index Then you will get a run time
error .
 Result := ARRAYLEN(<array variable>)
 ARRAYLEN(SaleAmount)
 IF Counter <= ARRAYLEN(SaleAmount) THEN
SaleAmount[Counter] := Answer;
Strings as Arrays of Characters
 Str := ‘Walk in the park’;
Str[13] := ‘d’;
MESSAGE(Str);
Output :Walk in the dark
Repetitive Statements
 A repetitive statement is a statement that enables execution
of one or more statements multiple times.
 The FOR Statement
FOR <control variable> := <start value> TO <end value> DO
<statement>
FOR idx := 4 TO 8 DO
Total := Total + 2.5;
FOR <control variable> := <start value> DOWNTO <end value> DO
<statement>
FOR Number:= 10 DOWNTO 5 DO
MESSAGE(FORMAT(Number));
The WHILE...DO Statement
 WHILE <Boolean expression> DO <statement>
 When Boolean Expression is true statement is
executed. And if the expression is False statement
skipped.
The REPEAT...UNTIL Statement
 Use the REPEAT statement when one or more statements
are to be executed until some condition becomes true.
 REPEAT
<statement> { ; <statement> }
UNTIL <Boolean expression>
Number :=10;
REPEAT
MESSAGE(FORMAT(Number));
Number:=Number-1;
UNTIL Number=2.;
WITH Statement
 When you work with records, addressing is created as
record name, dot (period), and field name:
 <Record>.<Field>
 If you work continuously with the same record, then
you can use WITH statements. When you use a WITH
statement, you only specify the record name once.
WITH Statement
CustomerRec."No." := '1234';
CustomerRec.Name := 'Windy City Solutions';
CustomerRec."Phone No." := '555-444-333';
CustomerRec.Address := '1241 Druid Avenue';
CustomerRec.City := 'Windy City'; MESSAGE('A variablehas been created for this
customer.');
WITH CustomerRec DO BEGIN
"No." := '1234';
Name := 'Windy City Solutions';
"Phone No." := '555-444-333';
Address := '1241 Druid Avenue';
City := 'Windy City'; MESSAGE('A variable has been created for this customer.');
END;
Demonstrations
 Demonstration: Use Arrays and Repetitive Statements

More Related Content

What's hot

The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsTech
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrolsteach4uin
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__elseeShikshak
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in CRAJ KUMAR
 
Control structure C++
Control structure C++Control structure C++
Control structure C++Anil Kumar
 
Conditional statement
Conditional statementConditional statement
Conditional statementMaxie Santos
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programmingRabin BK
 
Pseudocode & flowchart examples
Pseudocode & flowchart examplesPseudocode & flowchart examples
Pseudocode & flowchart exampleshayrikk
 
Control Structures
Control StructuresControl Structures
Control StructuresGhaffar Khan
 
Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2alish sha
 

What's hot (20)

The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrols
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
Selection statements
Selection statementsSelection statements
Selection statements
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Control All
Control AllControl All
Control All
 
Control structure
Control structureControl structure
Control structure
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
 
Conditional statement
Conditional statementConditional statement
Conditional statement
 
Control statement-Selective
Control statement-SelectiveControl statement-Selective
Control statement-Selective
 
Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Pseudocode & flowchart examples
Pseudocode & flowchart examplesPseudocode & flowchart examples
Pseudocode & flowchart examples
 
Control Structures
Control StructuresControl Structures
Control Structures
 
Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2
 

Viewers also liked

education para el trabajo
education para el trabajo education para el trabajo
education para el trabajo percy85
 
Persimmon diseases A Lecture on ToT By Allah Dad Khan
Persimmon diseases    A Lecture on ToT By Allah Dad Khan Persimmon diseases    A Lecture on ToT By Allah Dad Khan
Persimmon diseases A Lecture on ToT By Allah Dad Khan Mr.Allah Dad Khan
 
Safe in India - Report
Safe in India - ReportSafe in India - Report
Safe in India - ReportRushLane
 
Luke Frazier Resume 9-22-15 (General)
Luke Frazier Resume 9-22-15 (General)Luke Frazier Resume 9-22-15 (General)
Luke Frazier Resume 9-22-15 (General)Luke Frazier
 
Quality, traceability and the role of the supply chain to ensure quality coff...
Quality, traceability and the role of the supply chain to ensure quality coff...Quality, traceability and the role of the supply chain to ensure quality coff...
Quality, traceability and the role of the supply chain to ensure quality coff...essp2
 
Priority task for staff
Priority task for staffPriority task for staff
Priority task for staffJon Nicholls
 
Behaviour & attendance
Behaviour & attendance Behaviour & attendance
Behaviour & attendance Jon Nicholls
 
Download Important general science questions and answers for ssc exam.pdf
Download Important general science questions and answers for ssc exam.pdfDownload Important general science questions and answers for ssc exam.pdf
Download Important general science questions and answers for ssc exam.pdfSSC Alert
 

Viewers also liked (10)

education para el trabajo
education para el trabajo education para el trabajo
education para el trabajo
 
Persimmon diseases A Lecture on ToT By Allah Dad Khan
Persimmon diseases    A Lecture on ToT By Allah Dad Khan Persimmon diseases    A Lecture on ToT By Allah Dad Khan
Persimmon diseases A Lecture on ToT By Allah Dad Khan
 
IV scientific conference trends in the development of modern jurisprudence Ju...
IV scientific conference trends in the development of modern jurisprudence Ju...IV scientific conference trends in the development of modern jurisprudence Ju...
IV scientific conference trends in the development of modern jurisprudence Ju...
 
Safe in India - Report
Safe in India - ReportSafe in India - Report
Safe in India - Report
 
Luke Frazier Resume 9-22-15 (General)
Luke Frazier Resume 9-22-15 (General)Luke Frazier Resume 9-22-15 (General)
Luke Frazier Resume 9-22-15 (General)
 
ROBZZ RES
ROBZZ RESROBZZ RES
ROBZZ RES
 
Quality, traceability and the role of the supply chain to ensure quality coff...
Quality, traceability and the role of the supply chain to ensure quality coff...Quality, traceability and the role of the supply chain to ensure quality coff...
Quality, traceability and the role of the supply chain to ensure quality coff...
 
Priority task for staff
Priority task for staffPriority task for staff
Priority task for staff
 
Behaviour & attendance
Behaviour & attendance Behaviour & attendance
Behaviour & attendance
 
Download Important general science questions and answers for ssc exam.pdf
Download Important general science questions and answers for ssc exam.pdfDownload Important general science questions and answers for ssc exam.pdf
Download Important general science questions and answers for ssc exam.pdf
 

Similar to CalStatementsNAV2013

10-Lec - Nested IF Statement.pptx
10-Lec - Nested IF Statement.pptx10-Lec - Nested IF Statement.pptx
10-Lec - Nested IF Statement.pptxAqeelAbbas94
 
Oracle - Program with PL/SQL - Lession 04
Oracle - Program with PL/SQL - Lession 04Oracle - Program with PL/SQL - Lession 04
Oracle - Program with PL/SQL - Lession 04Thuan Nguyen
 
nuts and bolts of c++
nuts and bolts of c++nuts and bolts of c++
nuts and bolts of c++guestfb6ada
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa Thapa
 
CHAPTER-3a.ppt
CHAPTER-3a.pptCHAPTER-3a.ppt
CHAPTER-3a.pptTekle12
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
11-ScriptsAndConditionals.ppt
11-ScriptsAndConditionals.ppt11-ScriptsAndConditionals.ppt
11-ScriptsAndConditionals.pptAnjali127411
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c languagechintupro9
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
C++ control structure
C++ control structureC++ control structure
C++ control structurebluejayjunior
 
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdf
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdfUNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdf
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdfKavitaShinde26
 
3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdfArkSingh7
 

Similar to CalStatementsNAV2013 (20)

10-Lec - Nested IF Statement.pptx
10-Lec - Nested IF Statement.pptx10-Lec - Nested IF Statement.pptx
10-Lec - Nested IF Statement.pptx
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
Oracle - Program with PL/SQL - Lession 04
Oracle - Program with PL/SQL - Lession 04Oracle - Program with PL/SQL - Lession 04
Oracle - Program with PL/SQL - Lession 04
 
Flow control in c++
Flow control in c++Flow control in c++
Flow control in c++
 
nuts and bolts of c++
nuts and bolts of c++nuts and bolts of c++
nuts and bolts of c++
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
 
CHAPTER-3a.ppt
CHAPTER-3a.pptCHAPTER-3a.ppt
CHAPTER-3a.ppt
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
11-ScriptsAndConditionals.ppt
11-ScriptsAndConditionals.ppt11-ScriptsAndConditionals.ppt
11-ScriptsAndConditionals.ppt
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
 
Chapter 04
Chapter 04Chapter 04
Chapter 04
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdf
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdfUNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdf
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdf
 
M C6java5
M C6java5M C6java5
M C6java5
 
Vb scripting
Vb scriptingVb scripting
Vb scripting
 
3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 

CalStatementsNAV2013

  • 1.
  • 2. The IF Statement  Use the IF statement to control if a part of the program executes. If the condition is TRUE, one set of one or more statement executes; and if the condition is FALSE, another set of one or more statements executes  IF <Boolean expression> THEN <statement>  IF Amount < 0 THEN Amount := -Amount;
  • 3. IF - THEN - ELSE  IF <Boolean expression> THEN <statement 1> ELSE <statement 2> IF Quantity <> 0 THEN UnitPrice := TotalPrice / Quantity ELSE UnitPrice := 0; ;
  • 4. The EXIT Statement  Code in a trigger executes sequentially from the top to the bottom  IF Quantity = 0 THEN EXIT; UnitPrice := TotalPrice / Quantity;
  • 5. Code Indentation  To indent several lines of code, select the lines, and then press TAB.  To indent several lines of code to the left, select those lines, and press SHIFT+TAB
  • 6. The CASE Statement  Use the CASE conditional statement when there are more than two possible values for the condition.  CASE <expression> OF <value set 1> : <statement 1>; <value set 2> : <statement 2>; <value set n> : <statement n>; [ELSE <statement n+1>] END
  • 7. CASE Example Number:=25; CASE Number OF 1,2,9: MESSAGE('1, 2, or 9.'); 10..100: MESSAGE('In the range from 10 to 100.'); ELSE MESSAGE('Neither 1, 2, 9, nor in the range from 10 to 100.'); END; Output: In the range from 10 to 100
  • 8. Compound Statements and Comments  A compound statement is multiple statements  A comment is a description that developers write in their code .  // this code comment  { line 1 line 2 line 3 }
  • 9. The Syntax of Compound Statements  BEGIN <statement> {; <statement>} END  IF Quantity <> 0 THEN BEGIN UnitPrice := ExtendedPrice / Quantity; TotalPrice := TotalPrice + ExtendedPrice; END;
  • 10. IF Quantity <> 0 THEN BEGIN UnitPrice := ExtendedPrice / Quantity; TotalPrice := TotalPrice + ExtendedPrice; END //No ; ELSE BEGIN UnitPrice := 0; EXIT; END; // ;
  • 11. Compound Statement by Using Nested IF Statements IF Amount <> 0 THEN IF Amount > 0 THEN Sales := Sales + Amount ELSE IF Reason = Reason::Return THEN IF ReasonForReturn = ReasonForReturn::Defective THEN Refund := Refund + Amount ELSE Credits := Credits + Amount ELSE Sales := Sales - Amount;
  • 12. To have organized code  Use correct indentation.  Use meaningful variable names  Do not use negative variable names (for example, DoNotDelete  Use Booleans to designate Yes or No choices.
  • 13. Demonstrations  Demonstration: Use the Conditional and Compound Statements in a Page (Page 12)  Practice: Nested IF (Page 21)  Lab 6.1: Use Conditional and Compound Statements (Page 23)
  • 14. Arrays  Arrays are complex variables that contain a group of variables with the same data type.  Simple data types only have a single value.  A complex data type has multiple values.  Number array with 10 elements 10 5 4 50 21 63 20 12 42 25
  • 16. How to clear Variable  CLEAR(<variable>);  For example, for a one-dimensional array named SaleAmount of type Decimal, use the following function call to set all elements in SaleAmount to zero  CLEAR(SaleAmount);
  • 17. Array Element Syntax  <identifier>[<index expression>{,<index expression>}]  Box[5] := 25;
  • 18. ARRAYLEN Function  In your array you have seven elements but you are trying to access 8th index Then you will get a run time error .  Result := ARRAYLEN(<array variable>)  ARRAYLEN(SaleAmount)  IF Counter <= ARRAYLEN(SaleAmount) THEN SaleAmount[Counter] := Answer;
  • 19. Strings as Arrays of Characters  Str := ‘Walk in the park’; Str[13] := ‘d’; MESSAGE(Str); Output :Walk in the dark
  • 20. Repetitive Statements  A repetitive statement is a statement that enables execution of one or more statements multiple times.  The FOR Statement FOR <control variable> := <start value> TO <end value> DO <statement> FOR idx := 4 TO 8 DO Total := Total + 2.5; FOR <control variable> := <start value> DOWNTO <end value> DO <statement> FOR Number:= 10 DOWNTO 5 DO MESSAGE(FORMAT(Number));
  • 21. The WHILE...DO Statement  WHILE <Boolean expression> DO <statement>  When Boolean Expression is true statement is executed. And if the expression is False statement skipped.
  • 22. The REPEAT...UNTIL Statement  Use the REPEAT statement when one or more statements are to be executed until some condition becomes true.  REPEAT <statement> { ; <statement> } UNTIL <Boolean expression> Number :=10; REPEAT MESSAGE(FORMAT(Number)); Number:=Number-1; UNTIL Number=2.;
  • 23. WITH Statement  When you work with records, addressing is created as record name, dot (period), and field name:  <Record>.<Field>  If you work continuously with the same record, then you can use WITH statements. When you use a WITH statement, you only specify the record name once.
  • 24. WITH Statement CustomerRec."No." := '1234'; CustomerRec.Name := 'Windy City Solutions'; CustomerRec."Phone No." := '555-444-333'; CustomerRec.Address := '1241 Druid Avenue'; CustomerRec.City := 'Windy City'; MESSAGE('A variablehas been created for this customer.'); WITH CustomerRec DO BEGIN "No." := '1234'; Name := 'Windy City Solutions'; "Phone No." := '555-444-333'; Address := '1241 Druid Avenue'; City := 'Windy City'; MESSAGE('A variable has been created for this customer.'); END;
  • 25. Demonstrations  Demonstration: Use Arrays and Repetitive Statements