LiteFlow LiteFlow
💒Home
📚Documents
💖Donation
🚀Plugin
  • About LiteFlow
  • Update Record
Community
Users
Gitee (opens new window)
Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
💒Home
📚Documents
💖Donation
🚀Plugin
  • About LiteFlow
  • Update Record
Community
Users
Gitee (opens new window)
Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
  • 🍤Introduction
  • 🍓Features
  • 🍟Quick Start(Hello world)

    • 🍄Notice
    • 🌿Springboot environment

      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
    • 🌱Spring environment

      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
    • 🌵Other environment

      • 🍄Notice
      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
  • 🍢Configuration item

    • 🍄Notice
    • 🌿Springboot environment
    • 🌱Spring environment
    • 🌵Other environment
  • 🗂Rules file

    • 📔Rules file format
    • 📕Local rule file
    • 📗Zookeeper source
    • 📘SQL database source
    • 📋Nacos source
    • 🗄Etcd source
    • 📙Custom source
  • 🔗General components

    • 📎Common component
    • ✂️Switch component
    • 📌If component
    • 🧬For component
    • ⛓While component
    • 🧿Break component
  • 🧩How to write EL rules

    • 🍄Notice
    • 🌴Serial mode
    • 🎋Parallel mode
    • 🌾Switch mode
    • 🌵If mode
      • IF with two arguments
      • IF with three arguments
      • ELSE expression
      • ELIF expression
    • 🌳Loop mode
    • 🍁Use sub chain
    • 🍂Use sub variables
    • 💐Complex example
    • 🌻About semicolons
    • 🌰About comments
    • 🐚Component Name Package
  • 🌮Data context

    • 🍄Notice
    • 🌯Definition and use
    • 🪶Pass initialized context
  • 🛩Flow executor

    • 🍄Notice
    • 🎡Executor method
    • 🎢Chain input parameter
    • 🎈LiteflowResponse object
  • 🍋Script component

    • 🍫Choose a script language
    • 🍕Define script component
    • 🌯Define file script
    • 🍣Interact with java
    • 🍘Dynamic refresh script
  • 🍇Declarative component

    • 🥭What is a declarative component
    • 🧅Class level declaration
    • 🥥Method level declaration
  • 🎲Dynamic rules

    • 🍄Notice
    • 🎯How to build
  • 🎨Advanced features

    • 🍒Pre & Finally components
    • 🥠Substitute component
    • 🍉Component Parameters
    • 🍑Component alias
    • 🍍Component tag
    • 🥝Component event
    • 🥑Implicit chain
    • 🍕Private delivery
    • 🍣Component retry
    • 🍖Smooth hot refresh
    • 🍪Component aspect
    • 🍡Step information
    • 🧊Exceptions
    • 🧇Printing details
    • 🧁Custom request id
    • 🌭Multiple type rules
    • 🥗Asynchronous thread pool
    • 🍿Custom component executor
    • 🍥Simple monitor
    • 🧉DTD in Xml
  • ⛱Test cases and demo

    • 🪁Test cases
    • 🪀Demo
  • 🪂Performance
  • v2.9.X文档
  • 🧩How to write EL rules
铂赛东
2022-08-26
Contents

🌵If mode

Starting from version 2.8.5, LiteFlow provides conditional expression combinations.

Conditional expression is a variant of switch expression, SWITCH selects one of multiple subitems based on logic. The conditional expression has only two sub-items, true and false, which is very useful in the process of dealing with certain businesses.

In fact, conditional expression is to become an if else in the language. It's just that there are some different usages in the LiteFlow EL syntax.

The first parameter of the following IF and ELIF requires the definition of a if component. For how to define it, please refer to the chapter If component.

# IF with two arguments

<chain name="chain1">
    THEN(
        IF(x, a),
        b
    );
</chain>

Flow chart

x is a conditional node. If it is true, the execution chain is x->a->b, and if it is false, it is x->b.

# IF with three arguments

<chain name="chain1">
    THEN(
        IF(x, a, b),
        c
    );
</chain>

Flow chart

x is a conditional node. If it is true, the execution chain is x->a->c, and if it is false, it is x->b->c.

# ELSE expression

LiteFlow also provides the ELSE expression, the IF with two arguments + ELSE expression is equivalent to the IF with three arguments, for example:

<chain name="chain1">
    IF(x, a).ELSE(b);
</chain>

It is equivalent to:

<chain name="chain1">
    IF(x, a, b);
</chain>

# ELIF expression

The usage of the ELIF keyword is actually similar to the else if in the java language. It can be used with multiple ELIF, It will be followed by an ELSE at the end, which is used to judge multiple conditions:

<chain name="chain1">
    IF(x1, a).ELIF(x2, b).ELIF(x3, c).ELIF(x4, d).ELSE(THEN(m, n));
</chain>

Flow chart

Those who have written code should have a good understanding of this expression.

notice one

It is worth noting that only the two arguments expression of IF can be followed by ELIF. If the IF with three arguments is followed by ELIF, the last expression will be overwritten by the expression of ELIF. for example:

<chain name="chain1">
    IF(x1, a, b).ELIF(x2, c).ELSE(d);
</chain>

In this way, even if x1 is false, it will not execute to b, and will judge x2. Although the framework does fault-tolerant processing, it is not recommended to write expressions in this way. It is easy to cause confusion in understanding.

notice two

In fact, the IF with three arguments can already express all possibilities, which can be done by nesting, for example:

<chain name="chain1">
    IF(
        x1,
        a, 
        IF(
            x2,
            b,
            IF(x3, c, d)
        )
    );
</chain>

But it is still not recommended that you write this way. Multiple nesting will be difficult to understand, so try to use ELIF instead.

Help us improve this document (opens new window)
last update: 2022/10/13, 00:02:27
🌾Switch mode
🌳Loop mode

← 🌾Switch mode 🌳Loop mode→

Theme by Vdoing | Copyright © 2020-2022 铂赛东 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式