Check if current entry is in loop and add class
Firstly, from the Craft docs on routing:


  If the URI matches an entry’s or category’s URI, the
  section’s/category group’s template will get loaded, and the matched
  element will be made available to the template via a pre-populated
  entry or category variable.


This means if the page you are viewing relates to an entry, Craft will have already created a variable called entry, which will contain the EntryModel for that entry, so it’s best to avoid re-assigning the entry variable in a template used for an entry to avoid confusion.

To address your question, you need to check if the current URL matches the URL of an entry in the loop, which you can do by checking against [craft.request.url][2] like this:

{% for catEntry in craft.entries.section('category_name').limit(4) %}
    {% if craft.request.url == catEntry.url %}
      &lt;p class="active"&gt;{{ catEntry.title }}&lt;/p&gt;
    {% else %}
      &lt;p&gt;{{ catEntry.title }}&lt;/p&gt;
    {% endif %}
{% endfor %}