1: "for" loops can be nested:

for i = 1:3;
for j = 1:2;
A(i,j) = i+j;
end
end

2: Combination of "for" and "if":

for i = 1:10;
if (i >= 5)
x(i) = i;
else
x(i) = 2*i;
end
end

3: "while" loop:

Equivalent to No.2,

i = 1;
while (i <= 10)
if (i >= 5)
x(i) = i;
else
x(i) = 2*i;
end
i = i+1;
end

4: Implement practise 2 (Page 31, Example 2);

practise2.m:

clear all;
close all;

N = 1;
x = 1.5;
y = x-1;
POWER = y;
TERM = y;
SIGN = -1;
M = 15;
SUM = 0;
TOL = 1.0e-5;

while (N <= M)
SIGN = -SIGN;
SUM = SUM+SIGN*TERM;
POWER = POWER*y;
TERM = POWER/(N+1);

if(abs(TERM) < TOL)
display(N);
return;
end

N = N+1;

end

display('Method Failed');


