Foundations of Information Processing: Making Algorithms: Fundamental Parts
Foundations of Information Processing: Making Algorithms: Fundamental Parts
Information Processing
Making algorithms:
fundamental parts
Consideration 1:
Control statements:
• Selection: conditional branching of the execution.
IF condition THEN statement1 ELSE statement2 ENDIF
FOR i:=1,2,...,N DO
statement
ENDFOR
k:=1
FOR i:=1,2,...,n DO
k:=k*i
ENDFOR
In case of n=3:
k i ”new k”
1 in the beginning
1 1 1*1=1 the 1st round of the loop
1 2 1*2=2 the 2nd round of the loop
2 3 2*3=6 the 3rd round of the loop
6 3 at the end
Post-test loop:
REPEAT
statement
UNTIL condition
k:=1 k:=1
i:=1 i:=1
WHILE i<=n DO REPEAT
k:=k*i k:=k*i
i:=i+1 i:=i+1
ENDWHILE UNTIL i>n
• Although the number of the names in the list was known, the
number of repetitions needed would not be known since it is
not known where the name is in the list (if there at all).
• Note that the condition in the WHILE statement can contain
many logical expressions.