Procedures: A procedure is a self-contained block of code that performs a specific task but does not return a value to the calling part of the program. They are useful for grouping related instructions, such as printing a menu or updating a database record.
Functions: Unlike procedures, functions perform a calculation or process and return a single value back to the main program. They are typically used for mathematical computations or data retrieval where the result is needed for further processing.
Parameters: Parameters are variables used within a subprogram to receive data from the calling code. They allow the same subprogram to operate on different data sets, making the code more modular and flexible.
| Feature | Procedure | Function |
|---|---|---|
| Return Value | None | Returns a single value |
| Primary Use | Performing an action | Calculating a result |
| Calling Method | Called as a standalone statement | Usually part of an expression or assignment |
| Loop Type | When to Use | Example Scenario |
| --- | --- | --- |
| FOR Loop | Fixed number of iterations | Processing every item in a list of 10 elements |
| WHILE Loop | Unknown number of iterations | Repeating a prompt until the user enters 'quit' |
Analyze the Marks: The number of marks assigned to a programming question often correlates with the number of logical steps or constructs required. A 6-mark question likely requires a combination of variable declaration, input, a loop, a condition, and an output.
Use Standard Notation: If the exam specifies a particular reference language, ensure you follow its syntax for loops and assignments. However, most examiners prioritize logical correctness over perfect syntax in high-level languages.
Dry-Run Your Logic: Before finalizing your answer, mentally trace the values of your variables through the code. This 'dry run' helps identify logic errors, such as off-by-one errors in loops or incorrect boolean conditions in selection statements.