0% found this document useful (0 votes)
6 views17 pages

Unit 2 - Imperative-Updated

The document discusses the imperative programming paradigm, which is characterized by programming with state and commands that modify the state, such as assigning values to variables and changing the contents of memory locations over time. It provides examples of imperative programming in early assembly languages and machine code as well as higher-level languages like FORTRAN and COBOL. The document also contrasts imperative programming with declarative programming and includes Python code demonstrations of imperative algorithms.

Uploaded by

Agnivesh Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views17 pages

Unit 2 - Imperative-Updated

The document discusses the imperative programming paradigm, which is characterized by programming with state and commands that modify the state, such as assigning values to variables and changing the contents of memory locations over time. It provides examples of imperative programming in early assembly languages and machine code as well as higher-level languages like FORTRAN and COBOL. The document also contrasts imperative programming with declarative programming and includes Python code demonstrations of imperative algorithms.

Uploaded by

Agnivesh Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

IMPERATIVE

PROGRAMMIN
G
PARADIGM
Topics
■ Program state, instructions to change the program state

■ Combining Algorithms and Data Structures

■ Imperative Vs Declarative Programming

■ Other Languages: PHP, Ruby, Perl, Swift

■ Demo: Imperative Programming in Python


INTRODUCTION
■ In a computer program, a variable stores the data.
The contents of these locations at anygivenpoint in
the
program’s execution are called the program’s state.
Imperative programming is characterized by programming with
state and commands which modify the state.

■ The first imperative programming languages


were machinelanguages.
Machine Language
■ Each instruction performs asa a very specific task, such
unit load, a jump, or an ALU operation on a
For of data in a CPU register or memory.
– rs,example:
r t, and rd indicat e regist er
– shamt gives a operands shift amount
– t he address immediat e fields cont ain an
or operand directly
Assembly Code
■ 10110000 01100001
■ Equivalent Assembly
code
■ B0
– 61 B0 - ‘Move a copy of the following valueinto
(AL is a register) AL’
– 61 is a hexadecimal representation of the
value01100001 – 97
■ Intel assembly language
■ MOV AL, 61h; Load AL with 97 decimal (61 hex)
Other Languages
■ FORTRAN(FORmula TRANslation) was the first high level
language to gain wide acceptance. It was designed for
s cie ntific applications and featured an algebraic notation, types,
subprograms, and formatted input/output.

■ COBOL Business Oriented Language) was designed


(COmmon atthe initiative of the U. S. Department of Defence
in 1959 and implemented in 1960 to meet the need
for bu siness data processing applications.

■ ALGO 60 (ALGorithmic Oriented Language) was designed


L 1960 by an international committee for use in
in
scie ntific problem solving
Evolutionary developments

PL / I to
Algol to PL /I COBOL to PL/I LISP to PL/I
FORTR
• Block • Subprograms
AN • File • Dynamic
structur • Formatted IO manipulation storage
e • Record allocatio
• Control n
statement • Linked
s structure
• Recursion s
OVERVIEW
■ In imperative a name may be
assigned to a value
programming, and later reassigned to
another value.
■ The of names and the associated in
values and the location of
collection control the
program constitute the state.
■ The state is a model of storage
whichis
logical an association between memory locations
and values.
■ A program in execution generates a sequence of
states.
■ The transition from one state to next is
the determined by assignment operations and sequencing
commands.
Highlights on
■ Assignment, ■ Imperative language

■ goto commands ■ Assertions

■ structured ■ Axiomatic semantics


programming
■ State
■ Command
■ Variables
■ Statement
■ Instructions
■ Procedure
■ Control structures
■ Control-flow
Declarative Vs Imperative
Declarative Vs Imperative
# Declarative

# Imperative
DEMO
An algorithm to add two
entered
numbersby user
Step 1: Start
Step 2: Declare variables num1, num2 and sum. Step
3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to
sum. sum←num1+num2
Step 5: Display sum

Step 6: Stop
Addition two numbers entered by
user
An Algorithm to Get n number, print the
same and find Sum of n numbers
Step 1: Start
Step 2: Declare variable sum = 0.
Step 3: Get the value of limit “n”.
Step 4: If limit is reached, goto Step 7 else goto Step 5 Step
5: Get the number from user and add it to sum Step 6: Goto
Step 4
Step 7: If limit is reached, goto Step 9 else goto Step 8 Step
8: Print the numbers
Step 9: Goto Step 7
Step 9: Display sum
Step 10: Stop

You might also like