Search code examples
c#.netfor-loopcontrol-structureunreachable-code

Unreachable Code Detected C#


Im trying to Post an unlimited number of likes but looping the cookies and proxies based on the how many cookies are stored in the array. Apparently i++ is unreachable code. What is the reason for that?

public void PostLikes()
{
   PostLike postLike = new PostLike();
   for (int i =0;i<this.cookies.ToArray().Length;i++)
   {
      for (int j = 0; ; j++)
      {
         postLike.PostLike(this.cookies[i], this.importedProxies[i], this.proxyUsernameTextbox, this.proxyPasswordTextbox, this.postsIds[j]);
      }
   }
}

Solution

  • And don't do this

    for (int i =0;i<this.cookies.ToArray().Length;i++)
    

    because

    this.cookies.toArray().Length
    

    its evaluating in every iteration of the for loop, you are making 'this.cookies' to array every time so just you get its length? :) You are increasing the complexity of the method