Introduction to programming languages
(recapitulation from the last lecture)
Flow control
-
Logical and relational operations
== equal to ~= not equal to < less than <= less than or equal to > greater than >= greather than or equal to ~ not && and || or & element-wise and | element-wise or
-
Condition
something that either holds, or does not hold
values: true or false, stored in logical variablesa == 3 3 == a (b < 3) & (b > 1) C = (b < 3) & (b > 1)
-
Control flow statements
C - condition, B, B1, B2 - blocks of statementsConditional statement
complete:if C B1 else B2 end if C B1 elseif B2 ... else B end
noncomplete:if C B end
Loop WHILE
number of repetitons is not known in advancewhile C B end
Loop FOR
number of repetitons is known in advancefor k = 1:n B end v = [1 3 12 -6]; for k = v disp(k) end
FOR command is a special case of the previous command WHILE:k = 1; while k<=n B k = k+1; end