Text-only
Table of Contents (
frame
/
no frame
)
(11) For and While Loops
For and While Loops
Similar to other programming languages
For - repeats loop a number of times based on index value
While - repeats loop until logical condition returns false
Can be nested
try:
a=100
for i=1:a
for j=1:a
x(i,j)=i^2+3*j +1;
end
end
done=false;
max=1300;
i=1;
while(~done)
y(i)= i^3*2+1
if y(i) >max
done=true;
end
i=i+1
end
For_and_While_Loops.src last modified Oct 17, 2007
Introduction
Table of Contents
(
frame
/
no frame
)
Printable
(single file)
© Dartmouth College