Loops/With multiple ranges: Difference between revisions
Content added Content deleted
(Added XPL0 example.) |
|||
Line 2,669: | Line 2,669: | ||
</pre> |
</pre> |
||
=={{header|XPL0}}== |
|||
<lang XPL0>func IPow(A, B); \Return A**B |
|||
int A, B; |
|||
return fix(Pow(float(A), float(B))); |
|||
int Prod, Sum, X, Y, Z, One, Three, Seven, J; |
|||
proc Block; |
|||
begin \ABS(n) = absolute value |
|||
Sum:= Sum + abs(J); \add absolute value of J. |
|||
if abs(Prod)<1<<27 & J#0 then Prod:=Prod*J; \PROD is small enough & J |
|||
end; \not 0, then multiply it. |
|||
begin \all variables are DECLARED as integers. |
|||
Prod:= 1; \start with a product of unity. |
|||
Sum:= 0; \ " " " sum " zero. |
|||
X:= +5; |
|||
Y:= -5; |
|||
Z:= -2; |
|||
One:= 1; |
|||
Three:= 3; |
|||
Seven:= 7; |
|||
for J:= -Three to 3*3*3 do [Block; J:= J+Three-1]; |
|||
for J:= -Seven to +Seven do [Block; J:= J+X-1]; |
|||
for J:= 555 to 550 - Y do Block; |
|||
for J:= 22 downto -28 do [Block; J:= J-Three+1]; |
|||
for J:= 1927 to 1939 do Block; |
|||
for J:= X downto Y do [Block; J:= J+Z+1]; |
|||
for J:= IPow(11,X) to IPow(11,X)+One do Block; |
|||
\SUM and PROD are used for verification of J incrementation. |
|||
Text(0, " Sum= "); IntOut(0, Sum); CrLf(0); \display strings to term. |
|||
Text(0, "Prod= "); IntOut(0, Prod); CrLf(0); \ " " " " |
|||
end</lang> |
|||
{{out}} |
|||
<pre> |
|||
Sum= 348173 |
|||
Prod= -793618560 |
|||
</pre> |
|||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |