Skip to content
Loading
  • Nitin Sontakke
    +2

    Hello Sachin,

    I believe OR condition means if either (not both) condition is false....

    Please correct me if I am wrong!

    +2
  • Sachin Singh
    +2
    @Nitin Sir, i have said the same thing, 
      Contion1                                      Condition2            Resultant
     F    F F
     F T T
     T F T
     T T T
     That code will not execute when both are false, otherwise will execute if anyone is true.
    +2
  • Nitin Sontakke
    +2
    Yes, perfect.
     
    Thanks!
    +2
  • Sachin Singh
    +1
    'OR' condition means if both conditions are false then the code inside braces will not execute otherwise will execute if any of the condition is true.
     
     here 
    1. buffer[p] == buffer[p + 1]  
    2. buffer[255] == buffer[256] may give you out of range if buffer[256] is not available.  
     
    +1
  • Rijwan Ansari
    +1
    Hi,
     
    Your logic will give this error because you are using p+1 in last loop as well. 
    Even in or condition, there will be execution.
     
    You can do another check and split into two separate if conditions 
    +1
  • Muhammad Imran Ansari
    +1
    You need to check the length of buffer in first condition because buffer[index + 1] and when reach
    to last index and after adding 1, code will throw the expected range exception.
    In second condition index should not be 0 because you are checking buffer[index-1] and when start from
    0 then due to index-1, code will throw the expected range exception. Try the following code:
    for (int p = 0; p < 256; p++)
    {
          if ((p != (buffer.Length - 1) && buffer[p] == buffer[p + 1]) || (p != 0 && buffer[p] == buffer[p - 1]))
          {
                //Code
          }
    }
    +1