Unit1 - Structured Theory and Demo
Unit1 - Structured Theory and Demo
Unit 1
Overview of the Unit
1. History
2. Overview
3. Component
4. Representations in different languages(C, C++, Java,
Python)
1. History
The Böhm-Jacopini theorem, also called structured
program theorem, stated that working out a function is possible
by combining subprograms in only three manners:
Executing one subprogram, and the other subprogram
(sequence) .
Executing one of two subprograms according to the value of
a Boolean expression (selection) .
Executing a subprogram until a Boolean expression is true
(iteration)
Some of the languages that initially used structured
approach are ALGOL, Pascal, PL/I and Ada.
Ex:-
Structograms use the following diagrams:
1.process blocks - Process blocks represent the simplest
actions and don’t require analysis. Actions are performed
block by block.
2.Branching blocks
Branching blocks are of two types – True/False or
Yes/No block and multiple branching block.
3.Testing loops
Testing loops allow the program to repeat one or
many processes until a condition is fulfilled. There are
two types of testing loops – test first and test last
blocks – and the order in which the steps are
performed is what makes them different.
3.2.Subroutine
Procedure,
Function
Routine
Method
Subprogram.
Callable unit- Generic term.
Block
Two types of blocks can be
distinguished based on their location
within a program:
block associated with a procedure
in-line block
Control structure – sequence, selection ,iteration and recursion.
(example for Control structure)
Recursion:
Recursion"; a statement is executed by repeatedly calling itself
until termination conditions are met. While similar in practice to
iterative loops, recursive loops may be more computationally
efficient, and are implemented differently as a cascading stack .
Examples of Structured Programming language are C, C+, C++, C#, Java, PERL, Ruby, PHP, ALGOL,
Pascal, PL/I and Ada
Examples of unstructured Programming language are JOSS, FOCAL, MUMPS, TELCOMP, COBOL
Control Structure - DECISION MAKING (PYTHON )
With the break statement we can stop the loop even if the
while condition is true:
Example - Exit the loop when i is 3:
OUTPUT
i=1 1
2
while i < 6: 3
print(i)
if i == 3:
break
i += 1
THE CONTINUE STATEMENT
A for loop is used for iterating over a sequence (that is either a list, a
tuple, a dictionary, a set, or a string)
Example
Print each fruit in a fruit list: OUTPUT
apple
fruits = ["apple", "banana", "cherry"] banana
cherry
for x in fruits:
print(x)
The for loop does not require an indexing variable to set beforehand
Looping Through a String
eference : https://www.w3schools.com/python/python_for_loops.asp