for i from 1 to 3 do
i;
end do;for i from 1 to 3 do
i, i**2;
end do;for i from 1 to 3 do
i;
i**2;
end do;
i;This is a 'for loop.' Saying, do something i number of times, and then stop.In the third exemple, i equals 4 afterward, because maple assigns i to increasingly larger numbersfor i from 0 to 30 by 7 do
i;
end do;The 'by 7' makes it count by 7 instead of 1 which it will do normallyA:=[2,3,6,8,4,2];for i from 1 to 6 do
A[i];
end do;for i from 1 to 6 do
A[i]**2;
end do;B:=[2,3,4,5,6,7];for i from 1 to 6 do
A[i], B[i];
end do; Below is a for loop within a for loopfor i from 1 to 6 do
for j from 1 to 6 do
print(A[i], B[j]);
end do;
end do;A;
nops(A);
op(A);
[op(A),5];Nops is a command that just states the number of numbers in a list. op take the list off of a list and just puts it as elements. This allows you to add things to a list when you want to.A:=[6,5,7,6,9,8,7,4,6,5,8];total:=0;
for i from 1 to nops(A)-1 do
total:= total + (A[i]+A[i+1])/2;
end do:
total;The nops(A) minus 1 deal keep maple from evealuating one more term than is asked for, ie. A[i+1] or A12otaltotal:=1:
for i from 1 to nops(A)-1 do
total:= total * (A[i]+A[i+1])/2;
end do:
total;You cannot start at 0 otherwise it will always be zero, this total was changed to 1for x in A do
x;
end do;This is a conveniently easier to write and useStudents:= [Haiji, Philipe, Ahukana];for s in Students do print (s); end do;for s in [3,4,5] do print (s); end do;for x in A do
for y in B do
evalf(print(x,y, sqrt(x**2+y**2)));
end do;
end do;