What is sub procedure? with example.

  • A sub procedure is a small, logical and manageable and functional part of a program that performs specific tasks and does not return a value to the calling module.
  • A sub procedure is needed to be declared before it is used in a program. A CALL statement is used to call the sub procedure in a program. A sub program is written with SUB....END SUB statement. 
Syntax:
CALL Name (arguments list)
    SUB Name (parameters list)
        statements
    END SUB
  • The SUB line shows the name of the procedure and parameters used in the procedure. When there is no parameters, the brackets after the name of the procedure are left empty.
  • The number of arguments and number of parameters should be same and same data types.
  • When no data has to be passed to a sub procedure then no parenthesis is request after the procedure name in the calling statement.
  • If the CALL keyword is omitted, then the parenthesis should be omitted around the argument list. In such case, the DECLARE statement should be declare before calling it or save the program and QBasic will automatically add a DECLARE statement.
      • Eg: CALL sum (a, b) can be written as sum (a, b).
For Example (Click)

Share :

Twitter
Back To Top

facebook main

counter

Powered by Blogger.