










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











Venn Diagram of branching
If Condition I (^) If Condition II
If Condition III
Otherwise we are in this space
Example #1: Assigning grades
If grade >= 90 `A'
If 80 > grade >= 70 `C'
If 90 > grade >= 80
`B'
If 70 > grade >= 60 `D'
If grade < 60 `F'
'(%) 5 D& & D& DD
= 5 &2 64>= 6 < ! ,*"N$
grade x( ) out ← "you get an A" if( x ≥ 90 ) out ← "you get a B" if( x ≥ 80 ) ∧(x < 90 ) out ← "you get a C" if( x ≥ 70 ) ∧(x < 80 ) out ← "you get a D" if( x ≥ 60 ) ∧( x < 70 ) out ← "you fail" if( x < 60 ) out
grade 50( ) ="you fail" grade 61( ) ="you get a D" grade 75( ) ="you get a C" grade 88( ) ="you get a B"
grade 93( ) ="you get an A"
= !
Even if one condition is found true, all other conditions are still checke
grade x( ) out ← "you get a D" ifx ≥ 60 out ← "you get a C" if x ≥ 70 out ← "you get a B" if x ≥ 80 out ← "you get a A" ifx ≥ 90 out ← "you fail" ifx < 60 out
grade 50( ) ="you fail" grade 61( ) ="you get a D" grade 75( ) ="you get a C"
grade 88( ) ="you get a B"
grade 93( ) = "you get a A"
for^ ∈ "*& & #, ??&&??3 8 % " # &!& # & # $ '(%) & && "$ * 5 &# ! 3 8 S #T" E & !& $# 6
for i ∈ 1 .. 5
vector i
←i
for i ∈ 1 .. 5
x s ← 0
s ←s +i
for i ∈ 0 .. 4
x = (^10)
:= i
s := 0
x s ←s +i
:=for i ∈ 0 .. 4
x = (^4)
sum n( ) s ← 0
s ←s +i
for i ∈ 0 ..n
s
sum 4( ) = (^10)
sum begin end( , ) s ← 0
s ←s +i
for i ∈begin ..end
s
sum 0 4( , ) = 10 sum 1 10( , ) = (^55)
= 5 & 2 6 0 - & 3,D& 8 3D 8 &
sum begin end( , ) s ← 0
s ← s + i ifi < 0 s ← s +i otherwise
for i ∈begin ..end
s
sum (− 4 , 4 ) = (^20)
sum begin end( , ) s ← 0
s ← s + i ifi < 0 continue otherwise
for i ∈begin ..end
s
sum (− 4 , 4 ) = 4 - 5 & & &! &!# = 5 &2@ 6 % & 3,D& 8 3D 8 ! , 6 , 6 6 & &
x
P
2 3 (3 ) 6
P Deflection Lx x EI
− = −
BeamDefl L NP( , , E, I,P) inc
xi ← 0 +(i − 1 )inc
defli
3 L⋅ (^) ( xi) 2 ⋅ (^) (x (^) i) 3 ← ⋅ −
for i ∈ 1 ..NP
x defl
results :=BeamDefl 20 10( , , E, I,P)
results
We've set up the output from the function to contain the two vectors: x-coordinates and deflections at those coordinates. They are placed as individual elements in a 2x1 vector. Note that when we display the contents of 'results', it tells us that each of the two elements are a 10x1 vector.
Thus 'results' is called a 'data structure'. The difference is that each element in a data structure can be a vector or matrix, not just a scalar. These elements are indexed just like a vector (with a subscript). In order to display and use the contents of the data structure, we need to assign a name to each of the elements in the data structure.
xaxis results 1 := defl results 2
0 10 20
0
defl
xaxis (^)
function v t( ,) j ← 1
j
function v t( ,) j ← 1 while
j
function v t( ,) j ← 1
j ←j + 1
while v (^) j ≤t
j
x
:=
function02 v t( ,) j ← 1
j ← j + 1 v i if ≤t
break otherwise
for i ∈ 1 ..length v( )
j
function02 x 4( , ) = (^3)
Find_Negative vec( ) stop ← 1 location ← 1
out_location ←location stop ← 0
if veclocation < 0
location ←location + 1
while stop 1
out_location
list
result :=Find_Negative list( )
result = 5
! 6 & /- E & , # 5 /-W & 5/- E# & -&"B> $ !(7 /- 5 , # & # # & E !& & & # /- # /X-# & & D/-# 5 "! 7 $ & # # 5 # -
2 3