Things you find inside a computer program/algorithm

- Consider the Euclid's Algorithm that we have learned:
         Repeat until (A == 0 or B == 0):
         {
            if ( A > B )
                replace A with the value (A - B)
            otherwise
                replace B with the value (B - A)
         }

         if ( A is not equal to 0 )
            The Greatest Common Divisor = A
         otherwise
            The Greatest Common Divisor = B

You can see that the algorithm contains 2 types of things !!

Things you find inside a computer program/algorithm

- (1) The computer algorithm/program contains commands a.k.a. statements:
         Repeat until (A == 0 or B == 0):         <--- Repetition statement
         {
            if ( A > B )                          <--- Conditional statement
                replace A with the value (A - B)  <--- Assignment statement
            otherwise
                replace B with the value (B - A)
         }

         if ( A is not equal to 0 )
            The Greatest Common Divisor = A
         otherwise
            The Greatest Common Divisor = B

Commands or "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 in 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 unit
- The program unit used to package/contain statements and variables that perform an important task is called:
  Function (in Python and C) or Method (in Java) Procedure Subroutine

Some programming language may group multiple functions into larger units; e.g.: a class in Python !

❮ ❯