---
tags:
    - "Else"
    - "If"
    - "Condition"
    - "Switch"
---

# Else If

[Control](index.md) / **Else If**

## Description

Checks a condition if the previous one failed and executes if it's true

## Parameters

| Name | Description |
| :--- | :---------- |
| Conditions | The conditions to check |
| Instructions | The instructions to run |

## Code

```cs
using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Title("Else If")]
    [Image(typeof(IconElseIf), ColorTheme.Type.Blue)]
    
    [Description("Checks a condition if the previous one failed and executes if it's true")]
    [Category("Control/Else If")]
    
    [Parameter("Conditions", "The conditions to check")]
    [Parameter("Instructions", "The instructions to run")]
    
    [Keywords("Else", "If", "Condition", "Switch")]
    
    [NestInnerList(nameof(m_Conditions))]
    [NestOuterList(nameof(m_Instructions))]
    
    [Serializable]
    public class InstructionCoreConditionElseIf : Instruction
    {
        [SerializeField] private Conditions m_Conditions = new Conditions();
        [SerializeField] private Instructions m_Instructions = new Instructions();

        protected override string GetTitle(GameObject source) => $"Else if {this.m_Conditions}";

        protected override async Awaitable Run(Args args)
        {
            if (!this.PreviousResult.IsSuccess &&
                this.m_Conditions.Check(args, Conditions.DEFAULT_OPERATION))
            {
                await this.m_Instructions.Run(args, this.ParentCancelToken);
                this.CurrentResult = InstructionResult.Success;
            }
            else
            {
                this.CurrentResult = InstructionResult.Failure;
            }
        }
        
        public override void OnCancel()
        {
            base.OnCancel();
            this.m_Instructions.Cancel();
        }
    }
}
```

