title: C# - Avoiding code repetition: Nested if Statement
body: <p>I need to look if a path is available, but only at the runtime. So if my program has checked that the file doesn't exist, it sets the invalidPath bool to "true", so that it doesn't jump in the "File.Exists..." query again, as long the program runs.</p>
  
  <p>The problem is: if I do it in that way like listed below, I see no possibility to avoid code redundancy. I need to show a message to inform the user about the missing file, but it isn't very elegant to use the same line(s) of code for both "if" cases. </p>
  
  <pre><code>private bool invalidPath = false
  
  if (!invalidPath)
      {
        if (File.Exists(temp))
        {
            //do code            
        }
        else
        {
            Show.MessageBox("no file found") 
            invalidPath = true   
        }
      }
      else
      {
         Show.Messagebox("no file found")   /*&lt;---thats redundant*/   
      }
  </code></pre>
  
  <p>I hope someone can give me an idea.</p>