Lecture 4
Lecture 4
Engineering Applications
(GENG-8030)
By:
Dr. Mohammad Hassanzadeh
Lecture number:
(4)
Winter 2023
Subjects
Conditional statements
for loop
While loop
if/else statements
• First, we learn about if/else to code conditional statements.
• The if statement's basic form is
• if logical expression
• statements
• end
• Every if statement must have an accompanying end statement. The
end statement marks the end of the statements that are to be executed
if the logical expression is true.
The else statements:
The basic structure for the use of the else statement is
if logical expression
statement group 1
else
statement group 2
end
if b~=c
disp('b~=c') %
Statement 1
else
disp('a~=c') %
Statement 2
end
Computational methods and modeling for engineering applications (GENG-8030) 4
Example 1
Example 2
The elseif statement:
a) 5960 (correct)
b) 1815
c) 6643
d) 3983
a) 0.89
b) 2.04 (correct)
c) 1.75
d) 3.21
a) 0.89
b) 2.04 (correct)
c) 1.75
d) 3.21