# Conditionals

Certain commands allow the use of conditional statements to allow the user to execute them only in certain cases.&#x20;

There are currently two supported conditional statements:

1. [#when](#when "mention")
2. [#while](#while "mention")

## `when`

The `when` statement allows a command to be executed only when one, or more, conditional statements are met.&#x20;

The check for the conditional statement is performed once upon evaluation of the command.

### Conditions

`when` supports four different conditions:

1. `visible` - run the command only `when` the proceeding selector element is visible
2. `notVisible` - run the command only `when` the proceeding selector element is NOT visible
3. `true` - run the command only `when` the given value is true or not empty
4. `platform` - run the command only `when` the platform is one of `android`|`ios`|`web`

These conditionals can be used individually or combined into a complex statement

### Supported Commands

The commands which can take the `when` statement are as follows:

* [runflow](https://docs.moropo.com/creating-tests/commands/runflow "mention")
* runScript (not yet supported by Moropo)

### Example

simple statement

```
- runFlow
    file: test.yaml
    when:
      visible:
        text: some text
```

complex statement

```
- runFlow
    file: test.yaml
    when:
      visible:
        text: some text
      notVisible:
         text: some different text
      true: ${SOME_VARIABLE == 'value'}
      platform: ios
```

## `while`

The `while` statement allows a command to  be executed only when one, or more, conditional statements are met.&#x20;

The check for the conditional statement is performed each time the conditional is not satisfied.

### Conditions

`while` supports four different conditions:

1. `visible` - run the command only `while` the proceeding selector element is visible
2. `notVisible` - run the command only `while` the proceeding selector element is NOT visible
3. `true` - run the command only `while` the given value is true or not empty
4. `platform` - run the command only `while` the platform is one of `android`|`ios`|`web`

These conditionals can be used individually or combined into a complex statement

### Supported Commands

The commands which can take the `while` statement are as follows:

* [repeat](https://docs.moropo.com/creating-tests/commands/repeat "mention")

### Example

simple statement

```
- repeat
    commands:
      - scroll:
        direction: DOWN
    while:
      visible:
        text: some text
```

complex statement

```
- repeat
   commands:
      - scroll:
        direction: DOWN
    while:
      visible:
        text: some text
      notVisible:
         text: some different text
      true: ${SOME_VARIABLE == 'value'}
      platform: ios
```
