Notice that 1 and 5 are a bit special. 1 is the first Fib number and 5 is the fifth.
As an idiom for "does an element of my sequence have a given property" consider:
Code:
for(int i = 0; i < ???A; i++) {
ele = calculate i-th element
if(hasProperty(ele)) {
return true;
}
}
return false;
In your case the property is "equaling
val". The thing I've denoted ???A is a value estimating "how many sequence elements need to be checked" and it has to be big enough. Notice you might find it easier to use a while loop - that's because it might not be so easy to decide how many sequence elements need to be checked, but it might be really easy to decide when to stop checking.
The basic difference between the pseudocode above and the code you posted is where you decide to return.