SlideShare a Scribd company logo
F1001 PROGRAMMING FUNDAMENTALS




    UNIT

      3

CONTROL STRUCTURE

 Sequential Control Structure
 Selection Control Structure
   Decision Control Structure




                                                30
F1001 PROGRAMMING FUNDAMENTALS


BLOCKS OF CODE
•       Every programming language consists of thousand of statements.
•       Thus, to simplify the execution of the programming language, all the statements in the programming
        language is divided into blocks of code that have specific functions.
•       Statement in a block of code is arranged sequentially in a program.
•       A block of code is a group of statements that performs one particular task.

•       The block is separated in several ways, like curly bracket “{“ and “}”, Begin and End statement and
        others.
•       Function is a block of code that has been assigned a name.
•       Function is used as reference and execution for a block of code.
•       Combination of blocks of code will produce a perfect program to be executed in a computer.
•       Since the program comes from the different blocks of code, so, the flow needs to be controlled.
•       Example of blocks of code:

                              void welcome ( )
                              {
                                                                                                BLOCK OF
    BLOCK                              printf (“****************************”);
                                       printf (“********WELCOME **********”);                     CODE
    SEPARATO                           printf (“****************************”);
    R                         }


PROGRAM FLOW
•       Program flow in computer is controlled by the control structure.
•       Control structure is a logical structure that controls the flow of instruction to be executed by computer.

•       Control structure uses single entry and single exit; meaning it has only one beginning and one ending.

•       There are three types of control structures:
        1.   Sequential control structure
        2.   Selection / decision control structure
             a)   If……endif
             b) If……else
             c)   Nested if
        3.   Looping control structure
             a)   For
             b) While
             c)   Do……while




                                                                                                               31
F1001 PROGRAMMING FUNDAMENTALS



Sequential Control Structure
   In this control, every step will be executed one by one from top to bottom.
   Every box in control structure is a process. Every process is done sequentially.
   Format:
                  Pseudocode:

                                                                      START
                   Start

                                                      Flowchart     Statement A
                         Statement A
                         Statement B
                                                                    Statement B

                   End
                                                                       END


   Example 1:
     Compute the total overtime wages of an employee.
     Problem analysis:
        Input:
        o     Hours
        o     Basic_salary
        o     OT_rate
        Process:
        o     Overtime equals OT_rate times Hours
        o     Salary equals Basic_salary plus Overtime
        Output:
        o     Salary


     Algorithm:
        1.    Enter Hours, Basic_salary, OT_rate
        2.    Calculate overtime using formula:
                   Overtime = OT_rate * Hours
        3.    Calculate salary using formula:
                   Salary = Basic_salary + Overtime
        4.    Output Salary




                                                                                       32
F1001 PROGRAMMING FUNDAMENTALS



     Pseudocode:
        START
                       Input Hours, Basic_salary, OT_rate
                       Overtime = OT_rate * Hours
                       Salary = Basic_salary + Overtime
                       Output Salary
        END



     Flowchart:

                                          START


                                        Input Hours,
                                   Basic_salary, OT_rate


                              Overtime = OT_rate * Hours


                           Salary = Basic_salary + Overtime


                                         Output
                                         Salary

                                          END



   Example 2:
     Problem: Mathematical operation: Get two numbers, then do adding, subtracting, multiplying
        and dividing operations.
     Problem analysis:
        Input:
        o          number_1, number_2
        Process:
        o          Add 2 numbers:
            Sum = number_1 + number_2
        o          Minus 2 numbers:
            Subtract = number_1 – number_2
        o          Multiply 2 numbers:



                                                                                             33
F1001 PROGRAMMING FUNDAMENTALS


         Multiple = number_1 * number_2
    o         Division 2 numbers:
         Divide = number_1 / number_2
    Output:
    o         Sum, Subtract, Multiple and Divide


   Algorithm:
    1.   Enter 2 numbers
    2.   Add 2 numbers
              Sum = number_1 + number_2
    3.   Minus 2 numbers
              Subtract = number_1 – number_2
    4.   Multiply 2 numbers
              Multiple = number_1 * number_2
    5.   Division of 2 numbers
              Divide = number_1 / number_2
    6.   Display Sum, Subtract, Multiple and Divide


   Flowchart:

                                 START



                           Input number_1,
                              number_2


                   Sum = number_1 + number_2


                 Subtract = number_1 – number_2


                 Multiple = number_1 * number_2



                   Divide = number_1 / number_2



                  Output Sum, Subtract, Multiple,
                              Divide


                                 END


                                                                         34
F1001 PROGRAMMING FUNDAMENTALS



       Pseudocode:
        START
             Input number_1, number_2
             Sum = number_1 + number_2
             Subtract = number_1 - number_2
             Multiple = = number_1 * number_2
             Divide = number_1 / number_2
             Output Sum, Subtract, Multiple, Divide
        END




Selection / Decision Control Structure
   This type of control structure is usually used in structured programming
   This control structure will execute an instruction based on result of a condition or comparison.
   A condition will result either TRUE or FALSE.
   If the condition result is true, the control program will execute the instruction within the TRUE loop
    operation.
   Otherwise, it will execute the next instruction or the instruction within the FALSE loop operation.
   Example 1:
       Condition: A person can obtain a license when he/ she is above 21 years old
        Decision: If true then she / he is qualified to have driving license. If not he / she is not qualified to
        have a driving license.
       Below is a flowchart of control structure:




                                                                                                             35
F1001 PROGRAMMING FUNDAMENTALS




                                                                                         START


                                              True
                       Condition                                                    Input age


               False                             Statement that will be
                                                 executed if condition                            True
               Statement that will be                   is true                     If age > 21
               executed if condition
                    is not true                                                    False
                                                                                                     Output
                                                                                                   “Qualified”



                                                                                    Output “Not
                                                                                    Qualified”




                                                                                           END


   Type of selection / decision control structure:
    1.        If……endif
    2.        If……else
    3.        Nested if




         1.     IF…….ENDIF
                      Rules:

                                If (condition)
                                Instruction (do this instruction if condition is true)
                                Endif
                           If condition is not true, no instruction will be executed




                                                                                                                 36
F1001 PROGRAMMING FUNDAMENTALS




   Pseudocode:
    If (condition)
                                                         START
             True statement
    Endif
                                                                     True
                                                        Conditi
                                                                            Statement
                                                 Flowchart:on

                                                      False




                                                          END



   Example 1:
       Workers who work on shift 3 will receive additional Bonus RM50, where basic salary is
        entered by workers.
       Problem analysis:
        Input:       1. Shift
                     2. Basic_salary
             Process: Bonus equals RM 50
                         If Shift equals to 3:
                                  Salary equals Bonus plus Basic_salary
             Output: Salary


       Algorithm:
        1.   Enter Basic_salary, Shift
        2.   Bonus equals to RM 50
        3.   Check workers Shift
             3.1         If Shift equals to 3
                         Salary= Basic_salary + Bonus
        4.   Display Salary




                                                                                           37
F1001 PROGRAMMING FUNDAMENTALS




   Flowchart:

               START



      Input Shift, Basic_salary


            Bonus = 50



                              True
              If Shift =
                                        Salary = Basic_salary + Bonus
                  3
            False




            Output Salary



                 END


   Pseudocode:


    START
            Input Shift, Basic_salary
            Bonus = 50
            If (Shift ==3)
                       Salary = Basic_salary + Bonus
            End if
            Output Salary
    END




                                                                        38
F1001 PROGRAMMING FUNDAMENTALS




2.       IF…….ELSE type
        A selection of control structure is used to select between two options
                                                       Pseudocode:
        Rules:
                                                           If (condition)
         If (condition)
                                                                     True statement
                  True statement
                                                           Else
         Else
                                                                     False statement
                  False statement
                                                           Endif
         Endif


        Flowchart:


                                       START



                      False                                 True
                                        Conditi
                                          on



             Statement 2                                     Statement 1




                                            END

        Example 1:
         o     Prepare a problem analysis, algorithm, flowchart and pseudocode to identify whether a
               student is qualified to further her / his studies in any local university using his / her SPM
               grade equal to 1.


         o     Problem analysis:
                  Input: Grade
                  Process:         If Grade is equal to 1
                                              Output “Qualified to further study”.
                                   If not
                                              Output “Not qualified to further study”.
                  Output: Display message qualified or not




                                                                                                         39
F1001 PROGRAMMING FUNDAMENTALS



o   Algorithm:
        1.   Enter Grade
        2.   Check Grade
             1.1 If Grade = 1
                 1.1.1      Output “Qualified to further study”
             1.2 If not
                 1.2.1      Output “Not qualified to further study”


o   Flowchart:

                                 START


                              Input Grade



                 False                           True
                                   If
                                 Grade



    Output “Not qualified                      Output “Qualified
      to further study”                         to further study”




                                 END



o   Pseudocode:


        START
                 Input Grade
                 If (Grade==1)
                            Output “Qualified to further study”
                 Else
                            Output “Not qualified to further study”

                 Endif
        END



                                                                      40
F1001 PROGRAMMING FUNDAMENTALS



   Example 2:
    o    Problem:
            Prepare the problem analysis, algorithm, flowchart and pseudocode to find
            subtraction between two numbers that users enter.
    o    Problem analysis:
            Input:        num1, num2
            Process: If num1 greater than num2
                                     Result = num1 – num2
                          If not
                                     Result = num2 – num1
            Output:       Result


    o    Algorithm:
            1.   Enter num1, num2
            2.   Compare the 2 numbers
                 2.1 If num1 greater than num2
                      2.1.1    Result = num1 – num2
                 2.2 If not
                      2.2.1    Result = num2 – num1
            3.   Display Result


    o    Flowchart:

                                   START


                              Input num1, num2



             False                                     True
                                   If num1 >
                                      num2



Result = num2 – num1                                Result = num1 – num2




                               Output Result



                                     END                                          41
F1001 PROGRAMMING FUNDAMENTALS



         o    Pseudocode:


                  START
                              Input num1, num2
                              If num1 > num2
                                         Result = num1 – num2
                              Else

                                         Result = num2 – num1
                              Endif

                              Output Result

                  END


3.   NESTED IF


        There are 3 types:


         1.   Type 1:


                        If (condition1)
                                     If (condition2)
                                         If (condition3)
                                                         True statement
                                              Endif
                                     Endif
                        Endif


         2.   Type 2:
                        If (condition1)
                                     If (condition2)
                                              If (condition3)
                                                     Statement that will be executed if condition1, condition2
                                                     and condition3 are true
                                              Else
                                                     Statement that will be executed if condition1, and
                                                     condition2 are true but condition2 is false
                                              Endif



                                                                                                           42
F1001 PROGRAMMING FUNDAMENTALS


                               Else
                                      Statement that will be executed if condition1 is true but condition2
                                      and condition3 is false
                               Endif
                    Else
                             Statement that will be executed if condition1 is false
                    Endif



    3.       Type 3


             If (condition1)
                               Statement that will be executed if condition 1 is true
                    Else
                               If (condition 2)
                                          Statement that will be executed if condition2 is true but
                                          condition1 is false
                               Else
                                          If (condition3)
                                                   Statement that will be executed if condition3 is true
                                                   but condition1 and condition2 are false
                                          Else
                                                   Statement that will be executed if condition1,
                                                   condition2 and condition3 are false
                                          Endif
                               Endif
                    End if


   Example Type 1:
    o     Problem:
          To determine whether a candidate is qualified or not to get a scholarship based on his /
          her study years, guardian’s salary and student CGPA. If the study year is more than 1,
          student’s CGPA is not less than 3.00 and guardian’s salary is below than RM500,
          student will be considered for a scholarship.


    o     Problem analysis:
         Input: CGPA, Year, Salary.
         Process:


                                                                                                       43
F1001 PROGRAMMING FUNDAMENTALS


             1.    Check if the student application’s can be considered or not for a scholarship.
                   1.1 If Year greater than 1
                       1.1.1       If CGPA greater than or equal to 3.00
                                   1.1.1.1 If Salary is less than or equal to RM500
                                                Output “Your application is under consideration”.
             Output: Student status


         o    Algorithm:
              1.    Enter CGPA, Salary and Year
              2.    Check if the student application’s can be considered for a scholarship
                    2.11 If year > 1
                        2.1.1 If CGPA >= 3.00
                                   2.1.1.1   If salary <= RM500
                                                 Output “Your application is under consideration”
              3.1 Display status


         o    Flowchart:


              START


        Input Year, CGPA, Salary



False                              True
             If Year > 1


                           False      If CGPA        True
                                      >= 3.00

                                                                                  Output “Your
                                             False    If Salary      True
                                                                               application is under
                                                       <= 500
                                                                                 consideration”




                                             END




                                                                                                      44
F1001 PROGRAMMING FUNDAMENTALS



    o    Pseudocode:
            START
                      Input Year, CGPA, Salary
                      If Year >1
                      If CGPA >= 3.00
                                            If Salary <= RM500
                                                Output “Your application is under consideration”
                                            Endif
                                 Endif
                      Endif
            END


   Example Type 2:
    o    Problem:
        To determine whether a candidate is qualified or not to get a scholarship based on his /
        her study years, guardian’s salary and student CGPA. If the study year is more than 1,
        student’s CGPA is not less than 3.00 and guardian’s salary is below than RM500, student
        will be considered for a scholarship. If the student is not qualified the message “Not
        success” will be displayed.


    o    Problem analysis:
        Input: CGPA, Year, Salary
        Process:
              1.    Check if a student can be considered for a scholarship
                    1.1 If Year > 1
                        1.1.1      If CGPA >= 3.00
                                   1.1.1.1 If Gaji <= 500
                                                    Output “You application is under consideration”
                                   1.1.1.2 If not
                                                    Output “Not success”
                        1.1.2      If not
                                         Output “Not success”
                    1.2 If not
                              Output “Not success”
          Output: Student status




                                                                                                      45
F1001 PROGRAMMING FUNDAMENTALS



     o      Algorithm:
                1.    Enter CGPA, Year, Salary
                2.    Check if a student can be considered for a scholarship
                      2.1 If Year > 1
                            2.1.1       If CGPA >= 3.00
                                        2.1.1.1 If Salary <= RM500
                                                         Output “Your application is under consideration”.
                                        2.1.1.2 If not
                                                         Output “Not success”
                            2.1.2       If not
                                             Output “Not success”
                      2.2 If not
                                    Output “Not success”
                3.          Display status


     o      Flowchart:


               START


         Input Year, CGPA, Salary



 False                               True
              If Year > 1


Output “Not                 False       If CGPA           True
 success”                               >= 3.00

                                                                                      Output “Your
                     Output “Not                 False     If Salary     True
                                                                                   application is under
                      success”                              <= 500
                                                                                     consideration”

                                            Output “Not
                                             success”




                                                 END


                                                                                                             46
F1001 PROGRAMMING FUNDAMENTALS



    o   Pseudocode:
        Input CGPA, Salary, Year
        If (year > 1)
               If (CGPA >= 3.00)
                      If (salary <= RM500)
                             Output “Your application is under consideration”
                      Else
                             Output ”Not success”
                      Endif
               Else
                      Output ”Not success”
               Endif
        Else
               Output ”Not success”
        Endif


   Example Type 3:
    o    Problem: Education status is determined based on the GPA achievement under the
         following scheme:
                        GPA                          Status
                      3.50-4.00            Dean List
                      2.00-3.49            Pass
                      1.80-1.99            Conditional Pass
                      0.00-1.79            Fail

    o    Problem analysis:
         Input: GPA
         Process:
                 1. If (GPA < 0.00 AND GPA > 4.00)
                         Output “Invalid data”
                 2. If not
                     2.1 If (GPA >=3.5 AND GPA <= 4.00)
                              Output “Dean List”
                     2.2 If not
                         2.2.1 If (GPA >= 2.00 AND GPA < 3.50)
                                  Output “Pass”
                         2.2.2 If not
                                2.2.2.1 If (GPA >= 1.80 AND GPA< 2.00)
                                           Output “Conditional Pass”
                                2.2.2.2 If not
                                           Output “Fail”
         Output: Student education status




                                                                                          47
F1001 PROGRAMMING FUNDAMENTALS


o   Algorithm:
       1.   Enter student GPA
       2.   Compare student’s GPA to determine his/ her education status.
            2.1 If (GPA < 0.00 AND GPA > 4.00)
                     Output “Invalid data”
            2.2 If not
                 2.2.1       If (GPA >=3.50 AND GPA <= 4.00)
                                 Output “Dean List”
                 2.2.2       If not
                           2.2.2.1 If (GPA >= 2.00 AND GPA < 3.50)
                                            Output “Pass”
                           2.2.2.2 If not
                                      2.2.2.2.1If (GPA >= 1.80 AND GPA < 2.00)
                                                        Output “Conditional Pass”
                                      2.2.2.2.2If not
                                                        Output “Fail”
       3.   Print status




o   Flowchart:



                                                                                    48
F1001 PROGRAMMING FUNDAMENTALS




                  START


                Input GPA



   True                                False
               If GPA < 0.00
              && GPA > 4.00


                      True                                   False
                                 If GPA >= 3.50 &&
Output “Invalid                      GPA <= 4.00

    data”
                  Output “Dean                 True                          False
                                                        If GPA >= 2.00 &&
                     List”                                  GPA < 3.50


                                                                True                          False
                                                                        If GPA >= 1.80 &&
                                     Output “Pass”                          GPA < 2.00



                                                            Output
                                                                                     Output “Fail”
                                                       “Conditional Pass”




                                             END


          o     Pseudocode:
                   START
                   Input GPA
                       If ((GPA < 0.00) AND (GPA > 4.00))
                              Output "Invalid Data"
                       Else
                              If ((GPA >= 3.50) AND (GPA <= 4.00))
                                     Output "Dean List"
                              Else
                                     If ((GPA >=2.00) AND (GPA < 3.50))
                                            Output "Pass"
                                     Else


                                                                                                      49
F1001 PROGRAMMING FUNDAMENTALS


                                         If ((GPA >= 1.80) AND (GPA < 2.00))
                                                Output "Conditional Pass”
                                         Else
                                                Output "Fail"
                                         Endif
                                     Endif
                              Endif
                        Endif
                   END


          Usage of Logical Operator:
  Symbol           Symbol                    Example             Result                Description
(Pseudocode)    (C Language)
    AND               &&               (1 > 3) && (10 < 20)      FALSE      Both sides of the condition must
                                                                            be true
    OR                 ||               (1 > 3) || (10 < 20)      TRUE      Either one of the condition must
                                                                            be true
    NOT                 !                    ! (10 < 20)         FALSE      Change the operation either
                                                                            from true to false or vise versa

          o    From the above table, the logical operator are AND, OR and NOT.
          o    Example using of AND operator:


                       If ((a < b) && (c > d))
                              printf(“Print a and c”);




          o    If condition (a < b) is true AND condition (c > d) is true then “Print a and c” will be
               displayed. If one of the condition is not true then “Print a and c” will not be displayed.


          o    Example usage of OR operator:



                            If ((sales > 5000) || (hoursworked> 81))
                                    bonus = 500;
                            else
                                   bonus = 0;




                                                                                                            50
F1001 PROGRAMMING FUNDAMENTALS


            o       If the sales are more than 5000 OR working hours are more than 81, bonus RM500 will
                    be given. If either condition is not fulfilled, still the amount of RM500 will still be given
                    as bonus.
            o       If both conditions are false, then bonus will not be given.


Looping Control Structure
   A programming control structure that allows a series of instructions to be executed more than once.
    The similar statement is repeated several times until the conditions are fulfilled.
   Three are three types of loop:
       o     For
       o     While
       o     Do…while
                                       For                            While                  Do…while

                For (initialize; condition; counter)         While (condition)        Do
                    True statement if condition is              True statement          True statement
                    fulfilled                                Endwhile                 While (condition)
                Endfor

        o       Initialize value: a value to start a loop.
        o       Counter: to increase or decrease the initialize value.
        o       Rules for the condition:
                -         If the condition is true / fulfilled, the process will be performed.
                -         Then, the program loops back and recheck the condition, if the condition is true /
                          fulfilled, repeat the process.
                -         When the condition is false, then exit the loop.

                                                                       Format for Do …… while loop:
            Format for the For and While loops:

                      START                                                                 START


                     Initialize                                                            Initialize

                                                                                        Statement A

                        Test                 False
                                                       END                    True
                      condition                                                              Test
                                                                                           condition
                                True
                                                                                                 False
   Example of loops usage: A
                  Statement

                                                                                            END

                                                                                                               51
F1001 PROGRAMMING FUNDAMENTALS


o      Problem: Prepare the problem analysis, algorithm, flowchart and pseudocode for the average of 5
       numbers. Data will be entered by user.
o      Problem analysis:
      Input:      5 numbers
      Process: The process of adding numbers will repeat until the condition to exit the loop is met.
      Output: Average of 5 numbers
o      Algorithm:
      1.    Initialize Counter=0; Average = 0; Total = 0
      2.    Input number
      3.    Add Total using formula:
            Total = Total + number
      4.    Add Counter using formula:
            Counter = Counter + 1
      5.    Compare whether Counter is greater than 5
            If yes , go to step 6
            If not, go to step 2
      6.    Calculate Average of numbers using formula;
            Average = Total/5
      7.    Display Average




o          Pseudocode:
                 For loop                          While loop                       Do…while loop
    START                              START                                START
      no = 0                              no = 0                                no = 0
      Total = 0                           Total = 0                             Total = 0
      Avg = 0                             Avg = 0                               Avg = 0
      For (no=0; no<=5; no++)             While (no <= 5)                       Do {
            Input Num                           Input Num                           Input Num
            Total = Total + Num                 Total = Total + Num                 Total = Total + Num
      Endfor                                    no = no + 1                         no = no + 1
      Avg = Total/5                       Endwhile                              } While (no <= 5)
      Output Avg                          Avg = Total/5                         Avg = Total/5
    END                                   Output Avg                            Output Avg
                                       END                                  END



             o      Flowchart for For and While loops:




                                                                                                          52
F1001 PROGRAMMING FUNDAMENTALS




              START


              no = 0


             Total = 0


              Avg = 0



              For /           False
             While no                 Avg = Total/5
           True


            Input Num                 Output Avg



        Total = Total + Num               END


            no = no + 1




o   Flowchart for Do……while loop:



                                                          53
F1001 PROGRAMMING FUNDAMENTALS


                START
                                            Note:
                                                     no: a variable to control loop
                 no = 0                              structure whether to continue or
                                                     exit from the loop
               Total= 0
                                                     no + 1: a counter and it is very

                Avg = 0                              important. Without a counter, the
                                                     loop will be infinite

              Input Num
                                                     Total = Total + Num: a variable to
                                                     compute the value
         Total = Total + Num


               no = no + 1


True                             False
                no <= 5                       Avg = Total/5


                                             Output Avg


                                                   END



o      Example: To compute salary of 20 employees
       Algorithm for For and While loops:

        1.   Initialize Counter = 0, Salary = 0;
        2.   Compare whether Counter is greater than 20 or not
             If yes , out from the loop
             If not , go to step 3
        3.   Enter Basic_salary, Claim, O_time
        4.   Calculate EPF:
             EPF = Basic_salary * 0.09
        5.   Calculate Salary using this formula:
             Salary = Basic_salary + Claim + O_time – EPF
        6.   Display Salary
         7. Add Counter using the formula:
       Flowchart for For and While loops:
            Counter = Counter + 1
        8.   Back to step 2

                                                                                          54
F1001 PROGRAMMING FUNDAMENTALS



               START


               no = 0


              Salary = 0



               For /             False
                                           END
              While no
            True


                Input
            Basic_salary,
            Claim, O_time


     EPF = Basic_salary * 0.09



Salary = Basic_salary + Claim + O_time – EPF



           Output Salary



              no = no + 1


  Pseudocode for For loop:

     START
        no = 0
         Salary = 0
         For (no = 0, no <=20, no ++)
             Input Basic_salary, Claim, O_time
             EPF = Basic_salary * 0.09
             Salary = Basic_salary + Claim + O_time – EPF
             Output Salary
         Endfor
     END


  Pseudocode for While loop:



                                                            55
F1001 PROGRAMMING FUNDAMENTALS



     START
        no = 0
         Salary = 0
         While no <=20
              Input Basic_salary, Claim, O_time
              EPF = Basic_salary * 0.09
              Gaji = Basic_salary + Claim + O_time – EPF
              Output Salary
              no = no + 1
         Endwhile
     END




Algorithm for Do……while loop:

1.   Initialize Counter = 0, Salary = 0;
2.   Input Basic_salary, Claim, O_time
3.   Calculate EPF
     EPF = Basic_salary * 0.09
4.   Calculate Salary using this formula:
     Salary = Basic_salary + Claim + O_time – EPF
5.   Add Counter using this formula:
     Counter = Counter + 1
6.   Compare whether the Counter is greater than 20 or not
     If yes , out of loop
     If not, go to step 2
7.   Display Salary




Flowchart for Do…..while loop:



                                                             56
F1001 PROGRAMMING FUNDAMENTALS



                         START



                         no = 0


                       Salary = 0


                         Input
                     Basic_salary,
                     Claim, O_time

                EPF = Basic_salary * 0.09



    Salary = Basic_salary + Claim + O_time – EPF



                          Output
                          Salary


                        no = no + 1


         True                          False
                         no <= 5                    END



     Pseudocode for Do…..while loop:

     START
        no = 0
         Salary = 0
         Do
         {
                Input Basic_salary, Claim, O_time
                EPF = Basic_salary * 0.09
                Salary = Basic_salary + Claim + O_time – EPF
                Output Salary
                no = no + 1
        } While (no <= 20)
o    Dummy Data or Sentinel Value
     END


                                                                 57
F1001 PROGRAMMING FUNDAMENTALS


-    Value used to end the program. Dummy data must be different from the data
     to be entered.
-    Example:


    START
            Input name
            While name != “XXX”
                                               Dummy data
                      Output name
                      Input mark
                      Output mark
                      Input name
            Endwhile
    END




                                                                           58

More Related Content

What's hot

Jenis Kecederaan Ringan
Jenis Kecederaan RinganJenis Kecederaan Ringan
Jenis Kecederaan Ringan
PrasadSooryakumara
 
Taksanomi Pembelajaran.pdf
Taksanomi Pembelajaran.pdfTaksanomi Pembelajaran.pdf
Taksanomi Pembelajaran.pdf
Diana Antonius
 
kawalan berangka berkomputer CNC
kawalan berangka berkomputer CNCkawalan berangka berkomputer CNC
kawalan berangka berkomputer CNCAsrap Sanusi
 
BT F5 BAB 8 zila khalid =).pptx
BT F5 BAB 8 zila khalid =).pptxBT F5 BAB 8 zila khalid =).pptx
BT F5 BAB 8 zila khalid =).pptx
nursyafiqah663094
 
Peraturan keselamatan
Peraturan keselamatanPeraturan keselamatan
Peraturan keselamatan
Auroral Flame
 
1.konsep pergerakan mekanikal
1.konsep pergerakan mekanikal1.konsep pergerakan mekanikal
1.konsep pergerakan mekanikal
School (SMK TAMAN SERAYA,AMPANG)
 
Teknologi dan inovasi dalam pendidikan (slide)
Teknologi dan inovasi dalam pendidikan (slide)Teknologi dan inovasi dalam pendidikan (slide)
Teknologi dan inovasi dalam pendidikan (slide)
nuratikah1991
 
E4141 sistem kawalan 1 unit1
E4141 sistem kawalan 1 unit1E4141 sistem kawalan 1 unit1
E4141 sistem kawalan 1 unit1Asraf Malik
 
6 prosedur keselamatan komputer
6 prosedur keselamatan komputer 6 prosedur keselamatan komputer
6 prosedur keselamatan komputer
Joudrey Joel
 
Slide pengenalan komputer
Slide pengenalan komputerSlide pengenalan komputer
Slide pengenalan komputer
Wakakart
 
Teori kemoralan sosial
Teori kemoralan sosialTeori kemoralan sosial
Teori kemoralan sosialElyana Aziz
 
Bab 4 pengukuran ( mikrometer )
Bab 4 pengukuran ( mikrometer )Bab 4 pengukuran ( mikrometer )
Bab 4 pengukuran ( mikrometer )hasnul73
 
SISTEM EKZOS KENDERAAN
SISTEM EKZOS KENDERAANSISTEM EKZOS KENDERAAN
SISTEM EKZOS KENDERAAN
Jazli Firdaus Jamil
 
Smn 1013 topik 3 peralatan pengukuran, pengujian dan penandaan
Smn 1013   topik 3 peralatan pengukuran, pengujian dan penandaanSmn 1013   topik 3 peralatan pengukuran, pengujian dan penandaan
Smn 1013 topik 3 peralatan pengukuran, pengujian dan penandaan
Ayubkhan Kks
 
Bab 2 punca & pencegahan kemalangan
Bab 2 punca & pencegahan kemalanganBab 2 punca & pencegahan kemalangan
Bab 2 punca & pencegahan kemalanganSri Devi
 
Manupulasi alatan ppt
Manupulasi alatan  pptManupulasi alatan  ppt
Manupulasi alatan pptNadwah Khalid
 
Asas robotik (2)
Asas robotik (2)Asas robotik (2)
Asas robotik (2)halenna
 
7.5 kuasa
7.5 kuasa7.5 kuasa
7.5 kuasa
Ong Chee Kiong
 
Alat-alat pengukuran
Alat-alat pengukuranAlat-alat pengukuran
Alat-alat pengukuran
Yuseri Bujang
 

What's hot (20)

Jenis Kecederaan Ringan
Jenis Kecederaan RinganJenis Kecederaan Ringan
Jenis Kecederaan Ringan
 
Taksanomi Pembelajaran.pdf
Taksanomi Pembelajaran.pdfTaksanomi Pembelajaran.pdf
Taksanomi Pembelajaran.pdf
 
kawalan berangka berkomputer CNC
kawalan berangka berkomputer CNCkawalan berangka berkomputer CNC
kawalan berangka berkomputer CNC
 
Pengurusan Bengkel
Pengurusan BengkelPengurusan Bengkel
Pengurusan Bengkel
 
BT F5 BAB 8 zila khalid =).pptx
BT F5 BAB 8 zila khalid =).pptxBT F5 BAB 8 zila khalid =).pptx
BT F5 BAB 8 zila khalid =).pptx
 
Peraturan keselamatan
Peraturan keselamatanPeraturan keselamatan
Peraturan keselamatan
 
1.konsep pergerakan mekanikal
1.konsep pergerakan mekanikal1.konsep pergerakan mekanikal
1.konsep pergerakan mekanikal
 
Teknologi dan inovasi dalam pendidikan (slide)
Teknologi dan inovasi dalam pendidikan (slide)Teknologi dan inovasi dalam pendidikan (slide)
Teknologi dan inovasi dalam pendidikan (slide)
 
E4141 sistem kawalan 1 unit1
E4141 sistem kawalan 1 unit1E4141 sistem kawalan 1 unit1
E4141 sistem kawalan 1 unit1
 
6 prosedur keselamatan komputer
6 prosedur keselamatan komputer 6 prosedur keselamatan komputer
6 prosedur keselamatan komputer
 
Slide pengenalan komputer
Slide pengenalan komputerSlide pengenalan komputer
Slide pengenalan komputer
 
Teori kemoralan sosial
Teori kemoralan sosialTeori kemoralan sosial
Teori kemoralan sosial
 
Bab 4 pengukuran ( mikrometer )
Bab 4 pengukuran ( mikrometer )Bab 4 pengukuran ( mikrometer )
Bab 4 pengukuran ( mikrometer )
 
SISTEM EKZOS KENDERAAN
SISTEM EKZOS KENDERAANSISTEM EKZOS KENDERAAN
SISTEM EKZOS KENDERAAN
 
Smn 1013 topik 3 peralatan pengukuran, pengujian dan penandaan
Smn 1013   topik 3 peralatan pengukuran, pengujian dan penandaanSmn 1013   topik 3 peralatan pengukuran, pengujian dan penandaan
Smn 1013 topik 3 peralatan pengukuran, pengujian dan penandaan
 
Bab 2 punca & pencegahan kemalangan
Bab 2 punca & pencegahan kemalanganBab 2 punca & pencegahan kemalangan
Bab 2 punca & pencegahan kemalangan
 
Manupulasi alatan ppt
Manupulasi alatan  pptManupulasi alatan  ppt
Manupulasi alatan ppt
 
Asas robotik (2)
Asas robotik (2)Asas robotik (2)
Asas robotik (2)
 
7.5 kuasa
7.5 kuasa7.5 kuasa
7.5 kuasa
 
Alat-alat pengukuran
Alat-alat pengukuranAlat-alat pengukuran
Alat-alat pengukuran
 

Viewers also liked

Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchartlotlot
 
Flowchart pseudocode-examples
Flowchart pseudocode-examplesFlowchart pseudocode-examples
Flowchart pseudocode-examples
Gautam Roy
 
Programming in C++
Programming in C++Programming in C++
Programming in C++
Pooya Merat
 
GPA calculator and grading program in c++
GPA calculator and grading program in c++GPA calculator and grading program in c++
GPA calculator and grading program in c++
Taimur Muhammad
 
conditional statements
conditional statementsconditional statements
conditional statements
James Brotsos
 
C if else
C if elseC if else
C if else
Ritwik Das
 
Scientific calculator in c
Scientific calculator in cScientific calculator in c
Scientific calculator in c
Upendra Sengar
 

Viewers also liked (7)

Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchart
 
Flowchart pseudocode-examples
Flowchart pseudocode-examplesFlowchart pseudocode-examples
Flowchart pseudocode-examples
 
Programming in C++
Programming in C++Programming in C++
Programming in C++
 
GPA calculator and grading program in c++
GPA calculator and grading program in c++GPA calculator and grading program in c++
GPA calculator and grading program in c++
 
conditional statements
conditional statementsconditional statements
conditional statements
 
C if else
C if elseC if else
C if else
 
Scientific calculator in c
Scientific calculator in cScientific calculator in c
Scientific calculator in c
 

Similar to Unit 3

The IPO Model of Evaluation (Input-Process-Output)
The IPO Model of Evaluation (Input-Process-Output)The IPO Model of Evaluation (Input-Process-Output)
The IPO Model of Evaluation (Input-Process-Output)Janilo Sarmiento
 
Week 2PRG 218Variables and Input and Output OperationsWrite .docx
Week 2PRG 218Variables and Input and Output OperationsWrite .docxWeek 2PRG 218Variables and Input and Output OperationsWrite .docx
Week 2PRG 218Variables and Input and Output OperationsWrite .docx
co4spmeley
 
Lecture1
Lecture1Lecture1
Lecture1
Andrew Raj
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
Infinity Tech Solutions
 
Week 2PRG 218 Variables and Input and Output OperationsWrite.docx
Week 2PRG 218   Variables and Input and Output OperationsWrite.docxWeek 2PRG 218   Variables and Input and Output OperationsWrite.docx
Week 2PRG 218 Variables and Input and Output OperationsWrite.docx
melbruce90096
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
Cpp Homework Help
Cpp Homework Help Cpp Homework Help
Cpp Homework Help
C++ Homework Help
 
Exceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant BhabadExceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant Bhabad
vasant Bhabad
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 studrohassanie
 
optimization process on compiler
optimization process on compileroptimization process on compiler
optimization process on compilerSantosh Sahu
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptx
Chaya64047
 
Python Programming - III. Controlling the Flow
Python Programming - III. Controlling the FlowPython Programming - III. Controlling the Flow
Python Programming - III. Controlling the Flow
Ranel Padon
 
Lec1_EENG112-Introduction.pdf
Lec1_EENG112-Introduction.pdfLec1_EENG112-Introduction.pdf
Lec1_EENG112-Introduction.pdf
ShwetaSaharan8
 
Labsheet1 stud
Labsheet1 studLabsheet1 stud
Labsheet1 studrohassanie
 

Similar to Unit 3 (20)

Unit 3
Unit 3Unit 3
Unit 3
 
The IPO Model of Evaluation (Input-Process-Output)
The IPO Model of Evaluation (Input-Process-Output)The IPO Model of Evaluation (Input-Process-Output)
The IPO Model of Evaluation (Input-Process-Output)
 
Unit 2
Unit 2Unit 2
Unit 2
 
Week 2PRG 218Variables and Input and Output OperationsWrite .docx
Week 2PRG 218Variables and Input and Output OperationsWrite .docxWeek 2PRG 218Variables and Input and Output OperationsWrite .docx
Week 2PRG 218Variables and Input and Output OperationsWrite .docx
 
Penyelesaian masalah
Penyelesaian masalahPenyelesaian masalah
Penyelesaian masalah
 
Lecture1
Lecture1Lecture1
Lecture1
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Week 2PRG 218 Variables and Input and Output OperationsWrite.docx
Week 2PRG 218   Variables and Input and Output OperationsWrite.docxWeek 2PRG 218   Variables and Input and Output OperationsWrite.docx
Week 2PRG 218 Variables and Input and Output OperationsWrite.docx
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Cpp Homework Help
Cpp Homework Help Cpp Homework Help
Cpp Homework Help
 
Exceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant BhabadExceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant Bhabad
 
Labsheet 5
Labsheet 5Labsheet 5
Labsheet 5
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 stud
 
Labsheet2
Labsheet2Labsheet2
Labsheet2
 
optimization process on compiler
optimization process on compileroptimization process on compiler
optimization process on compiler
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptx
 
Python Programming - III. Controlling the Flow
Python Programming - III. Controlling the FlowPython Programming - III. Controlling the Flow
Python Programming - III. Controlling the Flow
 
Lec1_EENG112-Introduction.pdf
Lec1_EENG112-Introduction.pdfLec1_EENG112-Introduction.pdf
Lec1_EENG112-Introduction.pdf
 
Labsheet1 stud
Labsheet1 studLabsheet1 stud
Labsheet1 stud
 

More from rohassanie

Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012rohassanie
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6rohassanie
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2rohassanie
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2rohassanie
 
FP 202 - Chapter 5
FP 202 - Chapter 5FP 202 - Chapter 5
FP 202 - Chapter 5rohassanie
 
Chapter 3 part 2
Chapter 3 part 2Chapter 3 part 2
Chapter 3 part 2rohassanie
 
Chapter 3 part 1
Chapter 3 part 1Chapter 3 part 1
Chapter 3 part 1rohassanie
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3rohassanie
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3rohassanie
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2rohassanie
 
Chapter 2 (Part 2)
Chapter 2 (Part 2) Chapter 2 (Part 2)
Chapter 2 (Part 2) rohassanie
 
Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201rohassanie
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201rohassanie
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012rohassanie
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1rohassanie
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3 rohassanie
 

More from rohassanie (20)

Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
 
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
FP 202 - Chapter 5
FP 202 - Chapter 5FP 202 - Chapter 5
FP 202 - Chapter 5
 
Chapter 3 part 2
Chapter 3 part 2Chapter 3 part 2
Chapter 3 part 2
 
Chapter 3 part 1
Chapter 3 part 1Chapter 3 part 1
Chapter 3 part 1
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
Lab ex 1
Lab ex 1Lab ex 1
Lab ex 1
 
Chapter 2 (Part 2)
Chapter 2 (Part 2) Chapter 2 (Part 2)
Chapter 2 (Part 2)
 
Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012
 
Labsheet 4
Labsheet 4Labsheet 4
Labsheet 4
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3
 

Recently uploaded

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 

Unit 3

  • 1. F1001 PROGRAMMING FUNDAMENTALS UNIT 3 CONTROL STRUCTURE  Sequential Control Structure  Selection Control Structure  Decision Control Structure 30
  • 2. F1001 PROGRAMMING FUNDAMENTALS BLOCKS OF CODE • Every programming language consists of thousand of statements. • Thus, to simplify the execution of the programming language, all the statements in the programming language is divided into blocks of code that have specific functions. • Statement in a block of code is arranged sequentially in a program. • A block of code is a group of statements that performs one particular task. • The block is separated in several ways, like curly bracket “{“ and “}”, Begin and End statement and others. • Function is a block of code that has been assigned a name. • Function is used as reference and execution for a block of code. • Combination of blocks of code will produce a perfect program to be executed in a computer. • Since the program comes from the different blocks of code, so, the flow needs to be controlled. • Example of blocks of code: void welcome ( ) { BLOCK OF BLOCK printf (“****************************”); printf (“********WELCOME **********”); CODE SEPARATO printf (“****************************”); R } PROGRAM FLOW • Program flow in computer is controlled by the control structure. • Control structure is a logical structure that controls the flow of instruction to be executed by computer. • Control structure uses single entry and single exit; meaning it has only one beginning and one ending. • There are three types of control structures: 1. Sequential control structure 2. Selection / decision control structure a) If……endif b) If……else c) Nested if 3. Looping control structure a) For b) While c) Do……while 31
  • 3. F1001 PROGRAMMING FUNDAMENTALS Sequential Control Structure  In this control, every step will be executed one by one from top to bottom.  Every box in control structure is a process. Every process is done sequentially.  Format:  Pseudocode: START Start Flowchart Statement A Statement A Statement B Statement B End END  Example 1:  Compute the total overtime wages of an employee.  Problem analysis: Input: o Hours o Basic_salary o OT_rate Process: o Overtime equals OT_rate times Hours o Salary equals Basic_salary plus Overtime Output: o Salary  Algorithm: 1. Enter Hours, Basic_salary, OT_rate 2. Calculate overtime using formula: Overtime = OT_rate * Hours 3. Calculate salary using formula: Salary = Basic_salary + Overtime 4. Output Salary 32
  • 4. F1001 PROGRAMMING FUNDAMENTALS  Pseudocode: START Input Hours, Basic_salary, OT_rate Overtime = OT_rate * Hours Salary = Basic_salary + Overtime Output Salary END  Flowchart: START Input Hours, Basic_salary, OT_rate Overtime = OT_rate * Hours Salary = Basic_salary + Overtime Output Salary END  Example 2:  Problem: Mathematical operation: Get two numbers, then do adding, subtracting, multiplying and dividing operations.  Problem analysis: Input: o number_1, number_2 Process: o Add 2 numbers: Sum = number_1 + number_2 o Minus 2 numbers: Subtract = number_1 – number_2 o Multiply 2 numbers: 33
  • 5. F1001 PROGRAMMING FUNDAMENTALS Multiple = number_1 * number_2 o Division 2 numbers: Divide = number_1 / number_2 Output: o Sum, Subtract, Multiple and Divide  Algorithm: 1. Enter 2 numbers 2. Add 2 numbers Sum = number_1 + number_2 3. Minus 2 numbers Subtract = number_1 – number_2 4. Multiply 2 numbers Multiple = number_1 * number_2 5. Division of 2 numbers Divide = number_1 / number_2 6. Display Sum, Subtract, Multiple and Divide  Flowchart: START Input number_1, number_2 Sum = number_1 + number_2 Subtract = number_1 – number_2 Multiple = number_1 * number_2 Divide = number_1 / number_2 Output Sum, Subtract, Multiple, Divide END 34
  • 6. F1001 PROGRAMMING FUNDAMENTALS  Pseudocode: START Input number_1, number_2 Sum = number_1 + number_2 Subtract = number_1 - number_2 Multiple = = number_1 * number_2 Divide = number_1 / number_2 Output Sum, Subtract, Multiple, Divide END Selection / Decision Control Structure  This type of control structure is usually used in structured programming  This control structure will execute an instruction based on result of a condition or comparison.  A condition will result either TRUE or FALSE.  If the condition result is true, the control program will execute the instruction within the TRUE loop operation.  Otherwise, it will execute the next instruction or the instruction within the FALSE loop operation.  Example 1:  Condition: A person can obtain a license when he/ she is above 21 years old Decision: If true then she / he is qualified to have driving license. If not he / she is not qualified to have a driving license.  Below is a flowchart of control structure: 35
  • 7. F1001 PROGRAMMING FUNDAMENTALS START True Condition Input age False Statement that will be executed if condition True Statement that will be is true If age > 21 executed if condition is not true False Output “Qualified” Output “Not Qualified” END  Type of selection / decision control structure: 1. If……endif 2. If……else 3. Nested if 1. IF…….ENDIF  Rules: If (condition) Instruction (do this instruction if condition is true) Endif If condition is not true, no instruction will be executed 36
  • 8. F1001 PROGRAMMING FUNDAMENTALS  Pseudocode: If (condition) START True statement Endif True Conditi Statement Flowchart:on False END  Example 1:  Workers who work on shift 3 will receive additional Bonus RM50, where basic salary is entered by workers.  Problem analysis: Input: 1. Shift 2. Basic_salary Process: Bonus equals RM 50 If Shift equals to 3: Salary equals Bonus plus Basic_salary Output: Salary  Algorithm: 1. Enter Basic_salary, Shift 2. Bonus equals to RM 50 3. Check workers Shift 3.1 If Shift equals to 3 Salary= Basic_salary + Bonus 4. Display Salary 37
  • 9. F1001 PROGRAMMING FUNDAMENTALS  Flowchart: START Input Shift, Basic_salary Bonus = 50 True If Shift = Salary = Basic_salary + Bonus 3 False Output Salary END  Pseudocode: START Input Shift, Basic_salary Bonus = 50 If (Shift ==3) Salary = Basic_salary + Bonus End if Output Salary END 38
  • 10. F1001 PROGRAMMING FUNDAMENTALS 2. IF…….ELSE type  A selection of control structure is used to select between two options  Pseudocode:  Rules: If (condition) If (condition) True statement True statement Else Else False statement False statement Endif Endif  Flowchart: START False True Conditi on Statement 2 Statement 1 END  Example 1: o Prepare a problem analysis, algorithm, flowchart and pseudocode to identify whether a student is qualified to further her / his studies in any local university using his / her SPM grade equal to 1. o Problem analysis: Input: Grade Process: If Grade is equal to 1 Output “Qualified to further study”. If not Output “Not qualified to further study”. Output: Display message qualified or not 39
  • 11. F1001 PROGRAMMING FUNDAMENTALS o Algorithm: 1. Enter Grade 2. Check Grade 1.1 If Grade = 1 1.1.1 Output “Qualified to further study” 1.2 If not 1.2.1 Output “Not qualified to further study” o Flowchart: START Input Grade False True If Grade Output “Not qualified Output “Qualified to further study” to further study” END o Pseudocode: START Input Grade If (Grade==1) Output “Qualified to further study” Else Output “Not qualified to further study” Endif END 40
  • 12. F1001 PROGRAMMING FUNDAMENTALS  Example 2: o Problem: Prepare the problem analysis, algorithm, flowchart and pseudocode to find subtraction between two numbers that users enter. o Problem analysis: Input: num1, num2 Process: If num1 greater than num2 Result = num1 – num2 If not Result = num2 – num1 Output: Result o Algorithm: 1. Enter num1, num2 2. Compare the 2 numbers 2.1 If num1 greater than num2 2.1.1 Result = num1 – num2 2.2 If not 2.2.1 Result = num2 – num1 3. Display Result o Flowchart: START Input num1, num2 False True If num1 > num2 Result = num2 – num1 Result = num1 – num2 Output Result END 41
  • 13. F1001 PROGRAMMING FUNDAMENTALS o Pseudocode: START Input num1, num2 If num1 > num2 Result = num1 – num2 Else Result = num2 – num1 Endif Output Result END 3. NESTED IF  There are 3 types: 1. Type 1: If (condition1) If (condition2) If (condition3) True statement Endif Endif Endif 2. Type 2: If (condition1) If (condition2) If (condition3) Statement that will be executed if condition1, condition2 and condition3 are true Else Statement that will be executed if condition1, and condition2 are true but condition2 is false Endif 42
  • 14. F1001 PROGRAMMING FUNDAMENTALS Else Statement that will be executed if condition1 is true but condition2 and condition3 is false Endif Else Statement that will be executed if condition1 is false Endif 3. Type 3 If (condition1) Statement that will be executed if condition 1 is true Else If (condition 2) Statement that will be executed if condition2 is true but condition1 is false Else If (condition3) Statement that will be executed if condition3 is true but condition1 and condition2 are false Else Statement that will be executed if condition1, condition2 and condition3 are false Endif Endif End if  Example Type 1: o Problem: To determine whether a candidate is qualified or not to get a scholarship based on his / her study years, guardian’s salary and student CGPA. If the study year is more than 1, student’s CGPA is not less than 3.00 and guardian’s salary is below than RM500, student will be considered for a scholarship. o Problem analysis: Input: CGPA, Year, Salary. Process: 43
  • 15. F1001 PROGRAMMING FUNDAMENTALS 1. Check if the student application’s can be considered or not for a scholarship. 1.1 If Year greater than 1 1.1.1 If CGPA greater than or equal to 3.00 1.1.1.1 If Salary is less than or equal to RM500 Output “Your application is under consideration”. Output: Student status o Algorithm: 1. Enter CGPA, Salary and Year 2. Check if the student application’s can be considered for a scholarship 2.11 If year > 1 2.1.1 If CGPA >= 3.00 2.1.1.1 If salary <= RM500 Output “Your application is under consideration” 3.1 Display status o Flowchart: START Input Year, CGPA, Salary False True If Year > 1 False If CGPA True >= 3.00 Output “Your False If Salary True application is under <= 500 consideration” END 44
  • 16. F1001 PROGRAMMING FUNDAMENTALS o Pseudocode: START Input Year, CGPA, Salary If Year >1 If CGPA >= 3.00 If Salary <= RM500 Output “Your application is under consideration” Endif Endif Endif END  Example Type 2: o Problem: To determine whether a candidate is qualified or not to get a scholarship based on his / her study years, guardian’s salary and student CGPA. If the study year is more than 1, student’s CGPA is not less than 3.00 and guardian’s salary is below than RM500, student will be considered for a scholarship. If the student is not qualified the message “Not success” will be displayed. o Problem analysis: Input: CGPA, Year, Salary Process: 1. Check if a student can be considered for a scholarship 1.1 If Year > 1 1.1.1 If CGPA >= 3.00 1.1.1.1 If Gaji <= 500 Output “You application is under consideration” 1.1.1.2 If not Output “Not success” 1.1.2 If not Output “Not success” 1.2 If not Output “Not success” Output: Student status 45
  • 17. F1001 PROGRAMMING FUNDAMENTALS o Algorithm: 1. Enter CGPA, Year, Salary 2. Check if a student can be considered for a scholarship 2.1 If Year > 1 2.1.1 If CGPA >= 3.00 2.1.1.1 If Salary <= RM500 Output “Your application is under consideration”. 2.1.1.2 If not Output “Not success” 2.1.2 If not Output “Not success” 2.2 If not Output “Not success” 3. Display status o Flowchart: START Input Year, CGPA, Salary False True If Year > 1 Output “Not False If CGPA True success” >= 3.00 Output “Your Output “Not False If Salary True application is under success” <= 500 consideration” Output “Not success” END 46
  • 18. F1001 PROGRAMMING FUNDAMENTALS o Pseudocode: Input CGPA, Salary, Year If (year > 1) If (CGPA >= 3.00) If (salary <= RM500) Output “Your application is under consideration” Else Output ”Not success” Endif Else Output ”Not success” Endif Else Output ”Not success” Endif  Example Type 3: o Problem: Education status is determined based on the GPA achievement under the following scheme: GPA Status 3.50-4.00 Dean List 2.00-3.49 Pass 1.80-1.99 Conditional Pass 0.00-1.79 Fail o Problem analysis: Input: GPA Process: 1. If (GPA < 0.00 AND GPA > 4.00) Output “Invalid data” 2. If not 2.1 If (GPA >=3.5 AND GPA <= 4.00) Output “Dean List” 2.2 If not 2.2.1 If (GPA >= 2.00 AND GPA < 3.50) Output “Pass” 2.2.2 If not 2.2.2.1 If (GPA >= 1.80 AND GPA< 2.00) Output “Conditional Pass” 2.2.2.2 If not Output “Fail” Output: Student education status 47
  • 19. F1001 PROGRAMMING FUNDAMENTALS o Algorithm: 1. Enter student GPA 2. Compare student’s GPA to determine his/ her education status. 2.1 If (GPA < 0.00 AND GPA > 4.00) Output “Invalid data” 2.2 If not 2.2.1 If (GPA >=3.50 AND GPA <= 4.00) Output “Dean List” 2.2.2 If not 2.2.2.1 If (GPA >= 2.00 AND GPA < 3.50) Output “Pass” 2.2.2.2 If not 2.2.2.2.1If (GPA >= 1.80 AND GPA < 2.00) Output “Conditional Pass” 2.2.2.2.2If not Output “Fail” 3. Print status o Flowchart: 48
  • 20. F1001 PROGRAMMING FUNDAMENTALS START Input GPA True False If GPA < 0.00 && GPA > 4.00 True False If GPA >= 3.50 && Output “Invalid GPA <= 4.00 data” Output “Dean True False If GPA >= 2.00 && List” GPA < 3.50 True False If GPA >= 1.80 && Output “Pass” GPA < 2.00 Output Output “Fail” “Conditional Pass” END o Pseudocode: START Input GPA If ((GPA < 0.00) AND (GPA > 4.00)) Output "Invalid Data" Else If ((GPA >= 3.50) AND (GPA <= 4.00)) Output "Dean List" Else If ((GPA >=2.00) AND (GPA < 3.50)) Output "Pass" Else 49
  • 21. F1001 PROGRAMMING FUNDAMENTALS If ((GPA >= 1.80) AND (GPA < 2.00)) Output "Conditional Pass” Else Output "Fail" Endif Endif Endif Endif END  Usage of Logical Operator: Symbol Symbol Example Result Description (Pseudocode) (C Language) AND && (1 > 3) && (10 < 20) FALSE Both sides of the condition must be true OR || (1 > 3) || (10 < 20) TRUE Either one of the condition must be true NOT ! ! (10 < 20) FALSE Change the operation either from true to false or vise versa o From the above table, the logical operator are AND, OR and NOT. o Example using of AND operator: If ((a < b) && (c > d)) printf(“Print a and c”); o If condition (a < b) is true AND condition (c > d) is true then “Print a and c” will be displayed. If one of the condition is not true then “Print a and c” will not be displayed. o Example usage of OR operator: If ((sales > 5000) || (hoursworked> 81)) bonus = 500; else bonus = 0; 50
  • 22. F1001 PROGRAMMING FUNDAMENTALS o If the sales are more than 5000 OR working hours are more than 81, bonus RM500 will be given. If either condition is not fulfilled, still the amount of RM500 will still be given as bonus. o If both conditions are false, then bonus will not be given. Looping Control Structure  A programming control structure that allows a series of instructions to be executed more than once. The similar statement is repeated several times until the conditions are fulfilled.  Three are three types of loop: o For o While o Do…while For While Do…while For (initialize; condition; counter) While (condition) Do True statement if condition is True statement True statement fulfilled Endwhile While (condition) Endfor o Initialize value: a value to start a loop. o Counter: to increase or decrease the initialize value. o Rules for the condition: - If the condition is true / fulfilled, the process will be performed. - Then, the program loops back and recheck the condition, if the condition is true / fulfilled, repeat the process. - When the condition is false, then exit the loop.  Format for Do …… while loop:  Format for the For and While loops: START START Initialize Initialize Statement A Test False END True condition Test condition True False  Example of loops usage: A Statement END 51
  • 23. F1001 PROGRAMMING FUNDAMENTALS o Problem: Prepare the problem analysis, algorithm, flowchart and pseudocode for the average of 5 numbers. Data will be entered by user. o Problem analysis: Input: 5 numbers Process: The process of adding numbers will repeat until the condition to exit the loop is met. Output: Average of 5 numbers o Algorithm: 1. Initialize Counter=0; Average = 0; Total = 0 2. Input number 3. Add Total using formula: Total = Total + number 4. Add Counter using formula: Counter = Counter + 1 5. Compare whether Counter is greater than 5 If yes , go to step 6 If not, go to step 2 6. Calculate Average of numbers using formula; Average = Total/5 7. Display Average o Pseudocode: For loop While loop Do…while loop START START START no = 0 no = 0 no = 0 Total = 0 Total = 0 Total = 0 Avg = 0 Avg = 0 Avg = 0 For (no=0; no<=5; no++) While (no <= 5) Do { Input Num Input Num Input Num Total = Total + Num Total = Total + Num Total = Total + Num Endfor no = no + 1 no = no + 1 Avg = Total/5 Endwhile } While (no <= 5) Output Avg Avg = Total/5 Avg = Total/5 END Output Avg Output Avg END END o Flowchart for For and While loops: 52
  • 24. F1001 PROGRAMMING FUNDAMENTALS START no = 0 Total = 0 Avg = 0 For / False While no Avg = Total/5 True Input Num Output Avg Total = Total + Num END no = no + 1 o Flowchart for Do……while loop: 53
  • 25. F1001 PROGRAMMING FUNDAMENTALS START Note: no: a variable to control loop no = 0 structure whether to continue or exit from the loop Total= 0 no + 1: a counter and it is very Avg = 0 important. Without a counter, the loop will be infinite Input Num Total = Total + Num: a variable to compute the value Total = Total + Num no = no + 1 True False no <= 5 Avg = Total/5 Output Avg END o Example: To compute salary of 20 employees Algorithm for For and While loops: 1. Initialize Counter = 0, Salary = 0; 2. Compare whether Counter is greater than 20 or not If yes , out from the loop If not , go to step 3 3. Enter Basic_salary, Claim, O_time 4. Calculate EPF: EPF = Basic_salary * 0.09 5. Calculate Salary using this formula: Salary = Basic_salary + Claim + O_time – EPF 6. Display Salary 7. Add Counter using the formula: Flowchart for For and While loops: Counter = Counter + 1 8. Back to step 2 54
  • 26. F1001 PROGRAMMING FUNDAMENTALS START no = 0 Salary = 0 For / False END While no True Input Basic_salary, Claim, O_time EPF = Basic_salary * 0.09 Salary = Basic_salary + Claim + O_time – EPF Output Salary no = no + 1 Pseudocode for For loop: START no = 0 Salary = 0 For (no = 0, no <=20, no ++) Input Basic_salary, Claim, O_time EPF = Basic_salary * 0.09 Salary = Basic_salary + Claim + O_time – EPF Output Salary Endfor END Pseudocode for While loop: 55
  • 27. F1001 PROGRAMMING FUNDAMENTALS START no = 0 Salary = 0 While no <=20 Input Basic_salary, Claim, O_time EPF = Basic_salary * 0.09 Gaji = Basic_salary + Claim + O_time – EPF Output Salary no = no + 1 Endwhile END Algorithm for Do……while loop: 1. Initialize Counter = 0, Salary = 0; 2. Input Basic_salary, Claim, O_time 3. Calculate EPF EPF = Basic_salary * 0.09 4. Calculate Salary using this formula: Salary = Basic_salary + Claim + O_time – EPF 5. Add Counter using this formula: Counter = Counter + 1 6. Compare whether the Counter is greater than 20 or not If yes , out of loop If not, go to step 2 7. Display Salary Flowchart for Do…..while loop: 56
  • 28. F1001 PROGRAMMING FUNDAMENTALS START no = 0 Salary = 0 Input Basic_salary, Claim, O_time EPF = Basic_salary * 0.09 Salary = Basic_salary + Claim + O_time – EPF Output Salary no = no + 1 True False no <= 5 END Pseudocode for Do…..while loop: START no = 0 Salary = 0 Do { Input Basic_salary, Claim, O_time EPF = Basic_salary * 0.09 Salary = Basic_salary + Claim + O_time – EPF Output Salary no = no + 1 } While (no <= 20) o Dummy Data or Sentinel Value END 57
  • 29. F1001 PROGRAMMING FUNDAMENTALS - Value used to end the program. Dummy data must be different from the data to be entered. - Example: START Input name While name != “XXX” Dummy data Output name Input mark Output mark Input name Endwhile END 58