Variables,errors and control structures
Variables,errors and control structures
● GLOBAL ● LOCAL
VARIABLES VARIABLES
● Accessible from any ● Accessible only within
part of program. the function.
● Declared outside the ● Declared inside a
function. function.
● Have global scope ● Have local scope that
limited to the duration extends throughout
of the function. the program.
TYPES OF ERRORS
Following are the types of errors.
● SYNTAX ERRORS:
These are the errors in the syntax of
programming language.
example:
Missing semicolon , incorrect keyword
usage , mismatched brackets
● RUNTIME ERROR:
Errors occurring during program execution.
Example: Division of zero , null pointer exception
etc.
● LOGIC ERROR:
Errors in program’s logic that produce in correct
result.
Example: Incorrect algorithm , faulty conditional
statements , incorrect loop iterations.
● SEMANTIC ERRORS:
Errors in the meanings of a program.
Example: Using variable before declaration.
● COMPILATION ERRORS:
Errors occurring during the
compilation of a program are known
as compilation errors.
Example:
Syntax errors , missing header files.
CONTROL STRUCTURES
Programming constructs that allows
developers to dictate orders and
conditions in which specific instructions
are executed. These are categorized into
three types.
● SEQUENCE:
Executes instructions in straight line from
top to bottom. This means each instruction
is performed one after another without
looping.
● SELECTION:
Allows program to choose between different
paths based on the conditions. If –else and
switch statements are used to manipulate
different sets of instructions to be executed
based on different conditions.
● ITERATION:
Known as looping, enables to repeat specific
instructions multiple times. Looping control
structures like for, while and do-while are
extensively used to implement this behaviour.