---
title: if conditions must have different code blocks
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > if conditions must have different code blocks
---

# if conditions must have different code blocks

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site). ().
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `python-best-practices/condition-similar-block`

**Language:** Python

**Severity:** Warning

**Category:** Best Practices

## Description{% #description %}

Code in the branches of an `if` condition must be unique. If you have duplicated branches, merge the conditions.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```python
if foo:
  printf("bar")
elif baz:
  printf("bar2")
elif bap:
  # same code than the if condition
  printf("bar")
else:
  # same code than the if condition
  printf("bar")
```

## Compliant Code Examples{% #compliant-code-examples %}

```python
if foo:
  printf("bar")
elif baz:
  printf("bar2")
elif bap:
  printf("bar3")
else:
  printf("bar4")
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 