Things you find inside a computer program/algorithm

  • Consider the Euclid's Algorithm that we have learned:

       As long as neither number is equal to zero (0) do
       {
          if ( A > B )
              replace A with the value (A - B)
          otherwise
              replace B with the value (B - A)
       }
    
       if ( A > 0 )
          The Greatest Common Divisor is A
       otherwise
          The Greatest Common Divisor is B
      

You can see that the algorithm contains 2 kinds of "things"...

Things you find inside a computer program/algorithm

  • (1) The computer algorithm/program contains instructions a.k.a. statements:

       As long as neither number is equal to zero (0) do
       {
          if ( A > B )
              replace A with the value (A - B)
          otherwise
              replace B with the value (B - A)
       }
    
       if ( A > 0 )
          The Greatest Common Divisor is A
       otherwise
          The Greatest Common Divisor is B
      

Statements tell the computer what operation it needs to perform/execute

Things you find inside a computer program/algorithm

  • (2) The computer algorithm/program contains (memory) variables:

       As long as neither number is equal to zero (0) do
       {
          if ( A > B )
              replace A with the value (A - B)
          otherwise
              replace B with the value (B - A)
       }
    
       if ( A > 0 )
          The Greatest Common Divisor is A
       otherwise
          The Greatest Common Divisor is B
      

Variables store the necessary information used by the statements of the computer algorithm

Program organization (packaging)

  • Statements and variables are organized into coherent units to help programmers manage their program code:

      • Statements and variables that are used to perform an important task is grouped together into one program unit

  • The program unit used to package/contain statements and variables that perform an important task is called by different names:

      • Method (in Java)
      • Function (in C and Python)         or         
      • Procedure
      • Subroutine

Some programming language can group multiple (related) functions into larger units --- like a class in Java