Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^6: How do I write a program that calculates the sum of all numbers to a number, n?

by Tux (Canon)
on Feb 25, 2015 at 11:20 UTC ( [id://1117817]=note: print w/replies, xml ) Need Help??


in reply to Re^5: How do I write a program that calculates the sum of all numbers to a number, n?
in thread How do I write a program that calculates the sum of all numbers to a number, n?

say [+] ^$n,$n

(You do not want to change $n, so ++ is out of the question)

Also note that currently $n cannot be a native int when using ++, though that will be fixed.

$ perl6 -e'my Int $n = 10; say ++$n;' 11 $ perl6 -e'my int $n = 10; say ++$n;' Cannot assign to an immutable value in sub prefix:<++> at src/gen/m-CORE.setting:5565 in block <unit> at -e:1 $ perl6 -e'my int $n = 10; say [+] ^$n' 45 $ perl6 -e'my int $n = 10; say [+] ^$n,$n' 55

Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1117817]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found