Those kind of loops are well implemented by a do-while loop: you should write your code following this logic (you didn't specify any particular language, so I'll just write down the logic in pseudo code):
sum=0;
do {
num = prompt(number);
if(number>0) {
sum = sum+number;
}
while (number>0);
print(sum);
So, what we're doing is:
- Initialize the final sum as zero
- Ask the user for a number
- If the number is not negative, add it to the (partial) sum
- Loop steps 2-3 untile we get a negative value
- Print the final value of the sum