https://kotlinlang.org logo
Title
a

Ashutosh Panda

12/05/2019, 12:40 PM
the error is function should have return statement
d

diesieben07

12/05/2019, 12:40 PM
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

Ashutosh Panda

12/05/2019, 12:41 PM
So how to to do that
Ok let me try
What changes should I made
d

diesieben07

12/05/2019, 12:41 PM
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

Ashutosh Panda

12/05/2019, 12:42 PM
can't understand
s

Sergei Dubrov [JB]

12/05/2019, 12:42 PM
e.q. you can simply add return of some default value after for loop
d

diesieben07

12/05/2019, 12:42 PM
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

Ashutosh Panda

12/05/2019, 12:44 PM
If return any random value it affect my prog
leave I got it
Thanks
d

diesieben07

12/05/2019, 12:44 PM
Your code right now is equivalent to this:
return if (dataBase[0]?.accNo == accNo) {
            0
        } else {
            -1
        }
without any loop
a

Ashutosh Panda

12/05/2019, 12:44 PM
yes