Loops/With multiple ranges: Difference between revisions

no edit summary
(Realize in F#)
No edit summary
Line 1,383:
</lang>
 
=={{header|FutureBasic}}==
Note: This code uses NSInteger variables instead of int because NSInteger automatically adjusts to 32-bit or 64-bit Macintosh architecture. Also, since FB's abs() function takes either a legacy int or a float, this code uses a float for the abs() parameter to avoid a warning,
<lang futurebasic>
window 1, @"Loops with Ranges", ( 0, 0, 400, 400 )
 
begin globals
NSInteger sum = 0
float prod = 1
end globals
 
local fn process( x as float )
sum += abs(x)
if abs(prod) < (2 ^ 27) and x <> 0 then prod = prod * x
end fn
 
NSInteger j
NSInteger x = 5, y = -5, z = -2
NSInteger one = 1, three = 3, seven = 7
 
for j = -three to (3 ^ 3) step three: fn process(j): next j
for j = -seven to seven step x: fn process(j): next j
for j = 555 to 550 - y: fn process(j): next j
for j = 22 to -28 step -three: fn process(j): next j
for j = 1927 to 1939: fn process(j): next j
for j = x to y step z: fn process(j): next j
for j = (11 ^ x) to (11 ^ x) + one: fn process(j): next j
 
print using " sum = ###,###"; sum
print using "prod =-####,###,###"; prod
 
HandleEvents
</lang>
 
{{out}}
<pre>
sum = 348,173
prod = -793,618,560
</pre>
 
=={{header|Go}}==
715

edits