Introduction to
Imperative
Programming
RONNIE V. EDEC
Introduction
Imperative Programming is used by the most
professional programmers in their day-to-day jobs
or business.
It is also called as Procedural Programming language which includes the
programming languages like C, C++, Java, COBOL, etc.
we can tell the computer what exactly he has to do. For example “Computer, add
x & y,” or “Computer, present a dialog box onto the screen.”
Imperative programming focuses on describing how a program operates.
Uses a sequence of statements
State of program changes
Imperative Programming
01 Most widely used 03 Features closely related
paradigm to machine architecture
02 Oldest paradigm 04 Based on the von Neumann
stored program model
Language
Structure
Declarations
Expressions
Associate variables
with memory Evaluated in
the current
locations environment
Commands
Execution and
flow of control
Similar to the machine
instructions
Basis for defining an
effective programming
language
Turing Completeness
A programming language is said to be Turing Complete if it
contains
- Integer variables, values and operations
- Assignments, branching, sequencing, and conditionals
Other features make languages easier to program for
complex applications
- Loops
- Procedures
- Object Orientation
But they have the same power as any other
programming language
-i.e. what is possible to compute in one is possible in the
other
- Jay is Turing Complete
Other Features
Typical Turing complete language today supports
Data types for reals, chars, strings, booleans
For, while, switch
Arrays
Records
I/O commands
Pointers
Procedures and functions
Imperative Programming Design Principles
Structured Programming
The structure of the program text
should be the
guide to understanding what it does.
Can be more efficient Benefits
Improved readability
Easier to tune and modify Offer more services
Save cash
Efficiency
A language must allow an underlying Offer better services
assignment-oriented machine to be used
directly and efficiently.
Driving factor in the implementation of many
imperative languages
Types in Typical Imperative
Languages
Emphasis on data structures Storage allocated and
with assignable components deallocated explicitly
Based on values that can be Strongly typed
manipulated directly
by underlying machine
Size and layout fixed at Storage efficiency is the key
compile time
Naming and Variables
Reserved words Variables unique
Skipping
in Text
Concept of scope scoping rules
Types, Values and Expressions in Jay
Lets look at defining types, values, and expressions in Jay
Jay supports only two types
01 Boolean
02 Integer
• Values true,false Values ,-2,-1,0,1,2,..
Operations &&,|| , ! Operations
Arithmetic :+,-,*,/
Relational ==,!=,<=,<,>=,>
Type of an expression is defined by the types of its
constituents
Expressions in Jay Constituent Expression Type Expression Type
Value Type of the value
Expression has the forms Variable Type of the variable
Arithmetic Binary operator int
Relational Binary operator boolean
Unary operator boolean
01 Value
02 Variable
03 Result of a binary operation
04 Result of a unary operation
In imperitave languages, computations involve the state changes of named memory cells.
For example, consider the following C (an imperative language) program:
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{ int sum, count, n;
count = 0;
sum = 0;
while (1 == scanf("%d\n", &n))
{ sum = sum + n;
count++;
}
printf("%f\n", (float)sum / (float)count);
exit(0);
}
Thank You