Error, invalid loop
Description
Examples
In Maple, for loops and while loops must be terminated with end do (or od). This error occurs when there is no end do or od statement to terminate the loop.
Example 1
In the following example, the for loop contains only a controlling clause, and does not contain an end do or od statement to terminate the loop.
for i from 1 to 3 do
Solution:
Complete the statement and add end do or od to the end of the loop.
for i from 1 to 3 do printi end do
1
2
3
Example 2 The following example contains a loop that is intended to return a floating-point approximation to the sine function at the angles (measured in degrees) in the list L. However, pressing Enter to insert line breaks (and not Shift + Enter) after the controlling clause in the for loop generates an error.
L ≔ 23.4, 87.2, 43.0, 99.7:
for i in L do
Solution
To correct this error, press Shift + Enter to insert line breaks within the loop body instead of simply pressing Enter. Terminate the for loop with either an end do or an od statement.
for i in L do evalfsini*Pi/180; end do;
0.3971478907
0.9988061374
0.6819983600
0.9857034691
See Also
do
Download Help Document