Issue with "incompatible type" when returning a value from a for loop. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Issue with "incompatible type" when returning a value from a for loop.

The code is supposed to Generate the Fibonacci equivalent of the number inputted however the return call on my for loop is malfunctioning. I am given the debug issue of "incompatible return type" I am really really confused and would appreciate any help! https://code.sololearn.com/cI9UV6i8UE7P/?ref=app

24th Sep 2017, 12:17 AM
Damiano Marsili
3 Answers
+ 3
You have several issues with this code. For starters you haven't actually created a separate method to return a value from. Also the variable that you're attempting to return is not declared within the scope you are returning it from.
24th Sep 2017, 12:30 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Your for loop only runs if: i == fibPos i is set to 1 so the only way the for loop is entered is if and while fibPos is 1. This part of the if statement isn't even entered if fibPos is 1. Change your condition statement in the for loop so that it makes sense.
24th Sep 2017, 12:58 AM
ChaoticDawg
ChaoticDawg - avatar
0
Thank you! I have fixed this issue now so it is returning an answer however the answer now is simply whatever I initialize finalValue as.. any ideas as to where the issue is? https://code.sololearn.com/cI9UV6i8UE7P/?ref=app
24th Sep 2017, 12:49 AM
Damiano Marsili