Can the java gods of /g/ help a beginner out, I'm trying to use double for loops to make a pattern-matching method looking for a sub-string in a string. The example would be lets say find how many times "-bdc" occurs in "abdcbybdc" with '-' being any letter and printing every match into an ArrayList. My issue is I loop through everything but once something doesn't match and I need to jump into the outer loop the index should be one less than it is.
tldr; this is why pajeets are taking over
>>59546576
>needle
>haystack
what a pro lmao
>>59546602
thanks lmfao
>>59546576
>Initializing a Boolean with a condition
The fuck? Do people actually do this
>>59546576
you gonna go blind from this theme eventually
>>59546636
not trying to make it look clean just trying to make it work
>>59546576
>>59546636
Anyways....
Looks like your changing the index in the other conditions,
Possibly just add one to the index when it doesn't match
>>59546674
probably
>>59546686
Sorry minus from I***
>>59546703
this causes an infinite loop
>>59546576
Learn how to properly indent you fucking retard.
>>59546576
>java
>
>>59546576
>every line at same level of indent
>variables names
>decrementing i
This is why companies hire H1Bs.
>>59546576
>My issue is I loop through everything but once something doesn't match and I need to jump into the outer loop the index should be one less than it is.
Why are you changing i repeatedly in the inner loop? That makes things harder for you.
Also learn what break does.
>>59546576
Hi OP,
You should not change value of your iterators(i,j) inside "for" loops. It is not what they were designed for.
Also try to rewrite this and take different approach.
needleIndex = 0;
for( int i = 0; i < haystack.length(); i++)
{
//match
if(match)
{
//check if that was last match
//if yes then break out of the
// loop
ret += haystack[i];
//increase needleIndex
}
else
{
needleIndex = 0;
ret = "";
}
}