the error is function should have return statement
# announcements
a
the error is function should have return statement
d
The compiler cannot prove that the for loop will run at least once
So you have to handle the case where it is never run and provide a return value in that case, too
a
So how to to do that
Ok let me try
What changes should I made
d
Using a for loop here doesnt actually make any sense, since the first iteration will always return
So you could just do that first iteration's code, without any looping
a
can't understand
s
e.q. you can simply add return of some default value after for loop
d
inside the for loop you just always return something. So it never even gets to the x = 1 etc cases
1
So no point even doing a loop
a
If return any random value it affect my prog
leave I got it
Thanks
d
Your code right now is equivalent to this:
Copy code
return if (dataBase[0]?.accNo == accNo) {
            0
        } else {
            -1
        }
without any loop
a
yes