Your code as posted does not return what you have shown. As posted, the code returns 1.
As your “Expected output” looks like an array, you need to set up an array to fill and then return it at the end.
You have also made a mistake by putting the return inside the while loop. You also do not need so many variables, e.g. num and num1.
Start with something like this:
def looping(variable1)
result = [] # this creates an array to store the final result in
# -- your loop to fill the result array
return result # this returns the array of values
end
Now complete “your loop” to fill the result array with the values you want.
It looks like you need to put the numbers less than variable1 into the result array, so the while loop should be:
j = 0 # start value for loop is 0
while j < variable1 do # repeat loop until j == variable1
# put current value of j into result
j += 1 # make sure we increment j each loop
end
and the instruction to add a value to the right side of an array is push
So putting it all together gives:
def looping(variable1)
result = []
j = 0
while j < variable1 do
result.push(j)
j += 1
end
return result
end
```