<commit_before>---
title: Query using conditional logic
seotitle: Query using conditional logic in Flux
list_title: Conditional logic
description: >
  This guide describes how to use Flux conditional expressions, such as `if`,
  `else`, and `then`, to query and transform data. **Flux evaluates statements from left to right and stops evaluating once a condition matches.**
menu:
  flux_0_65:
    name: Conditional logic
    parent: Query with Flux
weight: 20
list_code_example: |
  ```js
  if color == "green" then "008000" else "ffffff"
  ```
---

Flux provides `if`, `then`, and `else` conditional expressions that allow for powerful and flexible Flux queries.

##### Conditional expression syntax
```js
// Pattern
if <condition> then <action> else <alternative-action>

// Example
if color == "green" then "008000" else "ffffff"
```

Conditional expressions are most useful in the following contexts:

- When defining variables.
- When using functions that operate on a single row at a time (
  [`filter()`](/flux/v0.65/stdlib/built-in/transformations/filter/),
  [`map()`](/flux/v0.65/stdlib/built-in/transformations/map/),
  [`reduce()`](/flux/v0.65/stdlib/built-in/transformations/aggregates/reduce) ).

## Evaluating conditional expressions

Flux evaluates statements in order and stops evaluating once a condition matches.

For example, given the following statement:

```js
if r._value >= 95.0000001 and r._value <= 100.0 then "critical"
else if r._value >= 85.0000001 and r._value <= 95.0 then "warning"
else if r._value >= 70.0000001 and r._value <= 85.0 then "high"
else "normal"
```

When `r._value` is 96, the output is "critical" and the remaining conditions are not evaluated.

## Examples

- [Conditionally set the value of a variable](#conditionally-set-the-value-of-a-variable)
- [Create conditional filters](#create-conditional-filters)
- [Conditionally transform column values with map()](#conditionally-transform-column-values-with-map)
- [Conditionally increment a count with reduce()](#conditionally-increment-a-count-with-reduce)
<commit_msg>edit from Scott on conditional logic<commit_after>---
title: Query using conditional logic
seotitle: Query using conditional logic in Flux
list_title: Conditional logic
description: >
  This guide describes how to use Flux conditional expressions, such as `if`,
  `else`, and `then`, to query and transform data. **Flux evaluates statements from left to right and stops evaluating once a condition matches.**
menu:
  flux_0_65:
    name: Conditional logic
    parent: Query with Flux
weight: 20
list_code_example: |
  ```js
  if color == "green" then "008000" else "ffffff"
  ```
---

Flux provides `if`, `then`, and `else` conditional expressions that allow for powerful and flexible Flux queries.

##### Conditional expression syntax
```js
// Pattern
if <condition> then <action> else <alternative-action>

// Example
if color == "green" then "008000" else "ffffff"
```

Conditional expressions are most useful in the following contexts:

- When defining variables.
- When using functions that operate on a single row at a time (
  [`filter()`](/flux/v0.65/stdlib/built-in/transformations/filter/),
  [`map()`](/flux/v0.65/stdlib/built-in/transformations/map/),
  [`reduce()`](/flux/v0.65/stdlib/built-in/transformations/aggregates/reduce) ).

## Evaluating conditional expressions

Flux evaluates statements in order and stops evaluating once a condition matches.

For example, given the following statement:

```js
if r._value > 95.0000001 and r._value <= 100.0 then "critical"
else if r._value > 85.0000001 and r._value <= 95.0 then "warning"
else if r._value > 70.0000001 and r._value <= 85.0 then "high"
else "normal"
```

When `r._value` is 96, the output is "critical" and the remaining conditions are not evaluated.

## Examples

- [Conditionally set the value of a variable](#conditionally-set-the-value-of-a-variable)
- [Create conditional filters](#create-conditional-filters)
- [Conditionally transform column values with map()](#conditionally-transform-column-values-with-map)
- [Conditionally increment a count with reduce()](#conditionally-increment-a-count-with-reduce)

{'fraction_non_alphanumeric': 0.11862367661212704, 'fraction_numerical': 0.03128007699711261, 'mean_word_length': 4.6024258760107815, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6711297', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1175, 'n_words': 447}