Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Control Structures

Similar presentations


Presentation on theme: "Basic Control Structures"— Presentation transcript:

1 Basic Control Structures
Sequence Selection Repetition

2 Sequence A process executed from one to another in a straightforward manner.

3 Example of Sequence Design a flowchart that will accept and display a number. Write its equivalent algorithms. Algorithm: Step 1: Read in the value of N. Step 2: Print the value of N. Start Read N Print N End

4 Example of Sequence 2. Draw a flowchart that will compute and display the sum and product of two numbers. Write its equivalent algorithm. Start Sum=0 Product=0 Read A,B Sum=A+B Product=A*B Print Sum, Product End Algorithm: Step 1:Initialize Sum and Product into 0. Step 2: Read in the values of A and B. Step 3. Compute Sum by adding A and B then compute Product by multiplying A and B. Step 4: Print the computed value of Sum and Product.

5 Selection (if – then – else)
A choice is provided between alternatives. C A B T F

6 Example of Selection Draw a flowchart that will input values for A and B. Compare two values inputted and print which of the values is higher including the remarks “Higher”. Write its equivalent algorithm.

7 Algorithm: Step 1: Read in the values of A and B. Step 2: Test if A is greater than B, A is higher. However, If A is less than B, B is higher. Step 3: Print the number and the remark “Higher”. Start Input A, B A > B Print B, Higher Print A, “Higher” End T F

8 Repetition (Looping) This structure provides for the repetitive execution of an operation or routine while the condition is true. The condition is evaluated before executing any process statement. As long as the condition is true, the process is executed, otherwise, control flows out of the structure.

9 C A F T Loop

10 Example of Repetition (Looping)
Construct a flowchart that will count from 1 to 10 and print each number counted using the do-while-repetition structure .Write its equivalent algorithm.

11 Example of Repetition (Looping)
Start C=0 C < 10 C = C + 1 F T Print C End Algorithm: Step 1: Initialize the value of C to 0. Step 2: Test if C is less than 10. Step 3: If C is less than 10, add 1 to the value of C, print the value then go back to Step 2. However, if C is greater than 10, stop processing.

12 Commonly Used Operators in Flowcharting
Arithmetic Operators + addition - Subtraction * Multiplication / Division

13 Commonly Used Operators in Flowcharting
Relational Operators = equal > Greater than < less than <> Not equal > Greater than or equal to < less than or equal to

14 Commonly Used Operators in Flowcharting
Logical operators && AND || OR ! NOT


Download ppt "Basic Control Structures"

Similar presentations


Ads by Google