Find and print the first string in a list:
>
|
L := [1, 2, "abc", "a", 7.0, infinity]:
|
>
|
for x in L do
if type(x, 'string') then
print(x);
break;
end if;
end do:
|
Print ordered pairs [1,1], [1,2], ..., [4,4], stopping after [2,3]:
>
|
for i to 4 do
for j to 4 do
print([i,j]);
if i = 2 and j = 3 then
break i; # alternatively, break 2;
end if;
end do;
end do:
|
Print each row of a Matrix, stopping after the first row containing a zero.
>
|
A := LinearAlgebra:-RandomMatrix(M,N):
|
| (3) |
>
|
for row to M do
print(A[row]);
for col to N do
break row if A[row,col] = 0;
end do;
end do:
|