In the present case, indexOf() method is used.
The problem is that if my variable contains a value like SD06 & SD06(A) e.g. cdSD06xxSD06(A), and if I keep a while loop condition with method,
then, the code in the loop will be executed twice as it contains SD06 twice though I want to execute it just once as SD06 & SD06(A) are completely different from each other.
Answer the following question with one of: true or false.
I only want to find the first occurrence of the substring.
If you answered true, then there is no need for any sort of loop. And, by the way, an if statement is not considered a "loop". If the intent is to conditionally execute code if the substring is found, then yes, an if statement is appropriate.