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

This satisfy all requiremts (It must contain a foreach or while command.) (modded from my evil answer to the almost same question)...
WinZ>perl -e " print eval join '+',(1..$ARGV[0]);exit while 1" 13 91


Serious answer: in some monk's signature there is something like: think a solution without a computer and then translate in our preferred language. for example: I have a Sum, empty for the moment. Then I expand numbers from 1 to GivenNumber (list expansion). Now for each number in the list I add it to Sum. I write down Sum.

HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
  • Comment on Re: How do I write a program that calculates the sum of all numbers to a number, n? (evil eval)
  • Download Code