Desired Language Characteristics - Data Typing
Desired Language Characteristics - Data Typing
do 100 i = 1, 50 do 100 i = 1. 50
J=j+1 J=j+1
100 continue 100 continue
Cont.
• Due to this error in FORTRAN compiler reads the intended do
statement as a perfectly legal assignment statement which leads to
an error in processing
• any variable that begins with the letter in the sequence a to h and o
to z is treated as a floating-point single-precision real number.
• While any variable begins with one of the letters k, l, m, n is
treated as an integer
Control Structures
•Sequential execution
•Selection (if-else statements)
•Iteration (loops)
•Conditional iteration (while, do-
while)
Control structures dictate how program
flow is managed. Sequential execution
follows a linear order. The selection allows
choosing paths based on conditions.
Iteration repeats a block of code until a
condition is met. Conditional iteration
combines selection and iteration for a
more complex control flow.
Cont.
• Most languages indirectly achieve a sequential execution of
instructions unless otherwise specified
• Decision structures providing if-then-else, for, and do-while clauses
are especially useful in providing correct readable code
• anyone who has programmed in C or Pascal will be familiar with
the structure
• the following examples are an if-then-else construct
if Y < 0 then
X :=4;
else if d = 0 then
X: = 6;
else
q: = 5;
end if
Cont.
The following example for –do loop;
for i in 0 …. 10 loop
d(i) :=i*j
end loop;
• Blocks
• Procedure and Functions
Cont.
•Breaking down complex problems into smaller, manageable modules
•Functions and procedures
•Encapsulation and information hiding
•Modularity and reusability
var i, x: integer;
begin
X:=0;
for i in 0…100 loop
block
var i : integer;
begin
For I in 1..5 loop
x:=x+i;
end loop;
end ;
end loop;
…….
Procedure and Functions
• The disadvantage of a block is that they must be explicitly
repeated every time they are needed
• In contrast a procedure or function can be written out once and
called whenever it is needed
• The entire program can be broken down into a set of procedures
and functions each of which may itself call other procedures and
functions
Cont.
for example, consider the following function