LAB-04 IF Structure I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.

Slides:



Advertisements
Similar presentations
Warm Up.
Advertisements

Selection Feature of C: Decision making statements: It allow us to take decisions as to which code is to be executed next. Since these statements control.
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Control Structures.
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
Chapter 6 Path Testing Software Testing
You can select between blocks of statements by using the selection construct IF statement is used as a selection construct Four types of IF constructs.
PHP Conditions MIS 3501, Fall 2014 Jeremy Shafer Department of MIS Fox School of Business Temple University September 11, 2014.
ITEC113 Algorithms and Programming Techniques
1 ICS 101 – LAB 2 Arithmetic Operations I Putu Danu Raharja kfupm.edu.sa Information & Computer Science Department CCSE - King Fahd University.
LAB-03 Logical Operations I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
true (any other value but zero) false (zero) expression Statement 2
LAB-05 Function I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
LAB-03 Logical Operations I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum.
ICS 101 – Introduction to Computer Programming I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
LAB-12 2-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
LAB-10 1-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
Vectors: planes. The plane Normal equation of the plane.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I.
COM S 207 IF Statement Instructor: Ying Cai Department of Computer Science Iowa State University
Homework Assignment #3 J. H. Wang Oct. 29, 2007.
Basic Of Computer Science
A Program is nothing but the execution of sequence of one or more Instructions. On the basis of application it is essential. To Alter the flow of a program.
You can select between blocks of statements by using the selection construct IF statement is used as a selection construct Four types of IF constructs.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
MS3304: Week 6 Conditional statements. Overview The flow of control through a script Boolean Logic Conditional & logical operators Basic decision making.
Flowcharts and Algorithms. Review of Terms  A computer is a machine that can represent and manipulate data –Ultimately the data and the instructions.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
MULTIPLE ALTERNATIVES IF… THEN… ELSEIF SELECT CASE.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Decision making statements. Decision making statements are used to skip or to execute a group of statements based on the result of some condition. The.
1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical operators: and, or, and not ❏ To understand how a C program.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
CSC115 Introduction to Computer Programming Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383
P ROBLEM SOLVING Design program using pseudocode and flowchart.
CSC115: Matlab Special Session Dr. Zhen Jiang Computer Science Department West Chester University.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
1 Conditional Statements + Loops ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem
Control Flow Statements
CSI 3125, Preliminaries, page 1 Control Statements.
LAB-09 DO WHILE loop I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I.
Introduction to Programming Python Lab 7: if Statement 19 February PythonLab7 lecture slides.ppt Ping Brennan
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
X y Cartesian Plane y axis x axis origin René Descartes ( ) Points and their Coordinates.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
Graphs and Applications of Linear Equations
Introduction to C++ Programming Language
Selection—Making Decisions
CSC115 Introduction to Computer Programming
Control Structures.
Cartesian Coordinate System
Conditional Statements
LAB-06 IF + Functions I Putu Danu Raharja
Topics discussed in this section:
Program Flow.
Computer Programming Basics
Repetition (While Loop) LAB 9
Design program using pseudocode and flowchart
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Graphing Ordered Pair – gives the location of a coordinate point
Presentation transcript:

LAB-04 IF Structure I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals

ICS101-LAB04-Term063 2 IF Structure What is the use of IF structure? What is the type of expression we can use for condition? Can we write multiple statements in an IF construct?

ICS101-LAB04-Term063 3 IF Constructs (1): IF (pp ) IF (condition) THEN STATEMENT_BLOCK ENDIF When is STATEMENT_BLOCK executed? What if condition is.FALSE.?

ICS101-LAB04-Term063 4 IF Construct(1) YES Is Condition.TRUE. ? STATEMENT_BLOCK NO

ICS101-LAB04-Term063 5 IF Constructs (2): IF-ELSE (pp ) IF (condition) THEN STATEMENT_BLOCK1 ELSE STATEMENT_BLOCK2 ENDIF When is STATEMENT_BLOCK1 executed? What about STATEMENT_BLOCK2?

ICS101-LAB04-Term063 6 IF Constructs (2): IF-ELSE (pp ) YES Is Condition.TRUE. ? STATEMENT_BLOCK2 NO STATEMENT_BLOCK1

ICS101-LAB04-Term063 7 IF Constructs (3): IF-ELSEIF (pp.38-42) IF (condition_1) THEN STATEMENT_BLOCK_1 ELSEIF (condition_2) THEN STATEMENT_BLOCK_2 … ELSEIF (condition_m) THEN STATEMENT_BLOCK_M ELSE STATEMENT_BLOCK_N ENDIF When is STATEMENT_BLOCK1 executed? What about STATEMENT_BLOCK2? What about STATEMENT_BLOCK_N?

ICS101-LAB04-Term063 8 IF Constructs (3): IF-ELSEIF (pp.38-42) YES Condition 1.TRUE. ? NO STATEMENT BLOCK1 YES Condition 2.TRUE. ? NO STATEMENT BLOCK2 YES Condition 3.TRUE. ? NO STATEMENT BLOCK3

ICS101-LAB04-Term063 9 IF Constructs (4): Simple IF (pp.42-44) IF (condition) statement The same as regular IF construct but it can only execute one statement When is statement executed?

ICS101-LAB04-Term Exercise-1 Implement the following flow diagram using a nested IF-ELSEIF structure.

ICS101-LAB04-Term Exercise-2 The National Earthquake Information Center has asked you to write a program implementing the following decision table to characterize an earthquake based on its Richter scale number. Richter Scale Number (N)Characterization N < 5.0 Little or no damage 5.0 <= N < 5.5 Some damage 5.5 <= N < 6.5 Serious damage; wall may crack or fall. 6.5 <= N < 7.5 Disaster; houses and buildings may collapse higher Catastrophe; most building destroyed.

ICS101-LAB04-Term Exercise-3 Write a program that takes the X-Y coordinates of a point in the Cartesian plane and displays a message telling either an axis on which the point lies or the quadrant in which it is found. Y X Q-1Q-2 Q-3 Q-4 Sample lines of output: (-1.0, -2.5) is in quadrant III (0.0, 4.8) is on the Y axis (5.6, 0.0) is on the X axis (0.0, 0.0) is on the center.