Jun-28-2025, 08:38 PM
Hello,
I am having trouble returning the correct values for my while loop.
The loop is supposed take in a value n and loop through "num times," if n > 1 then sum that value with the previous n and increment k to continue looping. However, if the n is ever 1 then the sum becomes 1 (sum = 1), but the statement should continuing looping until it has reached num times and then return sum=1.
My is issue is that loop terminates when it reaches 1 and returns 1 instead of completing the loop.
Is there a way to do this?
Thank you.
I am having trouble returning the correct values for my while loop.
The loop is supposed take in a value n and loop through "num times," if n > 1 then sum that value with the previous n and increment k to continue looping. However, if the n is ever 1 then the sum becomes 1 (sum = 1), but the statement should continuing looping until it has reached num times and then return sum=1.
My is issue is that loop terminates when it reaches 1 and returns 1 instead of completing the loop.
Is there a way to do this?
Thank you.
