I have a loop going through an array trying to find which index is a string. It should solve for what that value should be. I can\'t figure out why, but as soon as the if statem
As has been noted, in your if
statements, you are using the assignment operator (=
) but want the equality comparison operator (==
). For your variable i
the first if
statement sets i
equal to 0
and if(0)
is the same as if(false)
. So your program goes to the first else-if which sets i
equal to 1
and if(1)
evaluates to true. Your code then finishes the block within else if (i = 1) {...}
and then ends.