Another way of talking about this is to say that you need a loop, in which you ask for numbers, you must add those numbers together, you must look for a signal from the user that they are done putting in numbers, and then you must show the sum.
A while loop looks like this:
while(/* some test */) {
//some statements
}
In this case, you might want to use a time honored construction:
while(true) {
/// do some stuff
if /* some condition is true */ {
break
}
}
An important swiftism, alluded to above: since readLine returns an "optional", which is simply a regular type but could be "nil", you have to test for that. Swift demands that you handle this. Here's a way to do that:
If let inp = readLine() {
// do things with inp
} else {
// user entered an EOF
}
This sets the variable inp to a non-optional type, but only if the readLine() returns something other than nil. if it does return nil, the else clause is run instead.
You could use that as a signal, but if the user runs the program on the command line, they might not know how to send an EOF, so if might be better to use a character as a signal, like "=" or "q".
A word about optionals: An Int type can contain any integer from Int.min to Int.max. An Int? can contain and integer from Int.min to Int.max, or the special value nil. This means that a function which returns an integer has a way to say that it doesn't have a good answer, rather than giving you a wrong one.
Int.min, by the way is -9223372036854775808 on my machine.
Int.max is 9223372036854775807
I hope these clues help.