Flow Connect Help
Roadmap
  • ℹ️This is Flow Connect
    • Overview
    • Technical overview
      • System requirements
    • What's new?
      • Change log
  • ▶️quick start
    • Create an application
    • Create an admin access group
  • 🔁working with Connect
    • Connect to systems
      • Connector agents
        • Add agent group
        • Install agent manager
        • Add agent
        • Manage agent
      • Connectors
        • IFS Applications 10
        • Oracle
        • Microsoft SQL Server
        • Send Email
        • REST
          • Microsoft Graph API
          • Infor M3 REST
            • Obtaining Infor ION API file
            • Configure REST Connector with ION API file
          • IFS Cloud
            • IAM Client Registration
            • Obtaining end-point info from IFS Cloud
            • Configure REST Connector for IFS Cloud
        • File System
      • Redirect URIs
    • Create and design
      • Application packages
      • Applications
        • Create
        • Design
        • Test
        • Commit
      • Portal Pages
        • Create Portal Page
        • Design Portal Page
        • Commit Portal Page
      • Components
        • Create component
        • Manage component
      • Modules
        • Create module
        • Manage module
      • Automations
        • Functionality
        • Create Automation
        • Manage Automation
        • Creating Access Key
        • Executing Automations Externally
          • IFS Cloud
          • Salesforce Apex Trigger Example
    • Deploy
      • Environments
      • Deploy
    • Use
      • On mobile devices
      • In web browser - Web client
      • In web browser - Portal
    • Share
      • Share Applications
    • User administration
      • Users
        • Invite a new user
        • Manage users
      • User groups
        • Create user groups
        • Manage user groups
      • Access
        • Manage access
  • ⏸️Reference
    • How-to guides
      • Create User Step controls
        • Header
        • Static text
        • Labelled static text
        • Link
        • Image viewer
        • Text input
        • Numeric input
        • Date input
        • Time input
        • Check box input
        • Binary option input
        • List selection input
        • List multi-selection input
        • Menu selection input
        • Data grid
        • Calendar control
        • Image selection input
        • List presentation
        • Camera Input
      • Dependent controls in User step
        • Variable source
        • Expression source
        • Control visibility (condition to hide)
      • Configure SSO for Microsoft Entra
    • Reference
      • Clients
        • Settings
        • My data
      • Designer
        • Controls
          • Header
          • Static text
          • Labeled static text
          • Link
          • External app launcher
          • Image viewer
          • Text input
          • Numeric input
          • Date input
          • Time input
          • Check box input
          • Binary option input
          • List selection input
          • List multi-selection input
          • Menu selection input
          • Data grid
          • Calendar
          • Image selection input
          • List presentation
          • Camera input
          • File gallery
          • GPS location input
          • Signature capture input
          • Item creation sub task
          • Check list sub task
          • Verb sub task
        • Steps
          • Start
          • User interaction
          • External system
          • Decision
          • Assertion
          • HTTP requests
          • Assignment
          • Table
          • Event listener
          • Checkpoint
          • Script
          • Annotation
          • End
          • Local data resource
      • Portal
        • Design items
          • Portlets
            • Accumulation chart
            • Base chart
            • Circular gauge
            • Custom content
            • Data tree
            • Document viewer
            • Filter
            • Kanban
            • KPI card
            • Link
            • My apps
            • Record
            • Rich text
            • Table
          • Container
          • Common portlet configuration
            • General
            • Events
            • Data
            • Custom buttons
            • Style
        • Portal settings
          • Branding
          • Page
          • Navigation
        • Profile
        • Portlet actions
        • Cache
        • Input to Start Step
      • Diagnostic mode
      • FlowScript
        • Walkthrough
          • Introduction
          • Expressions and programs
          • Anatomy of a program
          • Variables
          • Simple types
          • Nullable types
          • Records
          • Sequences
          • Other types
          • Arithmetic
          • Other expressions
          • Queries
          • Conditionals and loops
          • Function definitions
          • Built-in functions
          • DateTime module
          • Seq module
          • HTTP module
          • CSV module
          • JSON module
          • Trace module
          • Record module
          • XML Module
          • Filesystem Module
          • Custom modules
          • Custom Types
          • Appendix: Subtyping rules
          • Appendix: Escape sequences
          • Appendix: Type checking errors
      • Flowscript Copilot
      • Glossary
    • Flow Connect Downloads
      • Install Flow Connect Designer
    • Migrate from Flow Classic
      • Portal - migrate from Flow Classic
      • Classic vs. Connect Comparison Guide
Powered by GitBook
On this page
  • Conditional statements
  • Loops
  • for loops
  • while loops
  • break
  • continue

Was this helpful?

  1. Reference
  2. Reference
  3. FlowScript
  4. Walkthrough

Conditionals and loops

Conditional statements

A conditional statement lets your program choose different paths depending on some (boolean) condition.

// Example: generate a random temperature between -100 and 200 degrees Celsius.
// Then, return the state of water in that temperature.

let degreesCelsius = random(-100, 200);

if degreesCelsius <= 0 {
    return "ice";
}
else if degreesCelsius > 100 {
    return "water vapour";
}
else {
    return "liquid water";
}

A conditional statement consists of an if block followed by zero to many else if blocks and, optionally, one else block. Each block, except the else block, has some guard condition which must be of type boolean. When executing a conditional statement, FlowScript finds the first block whose guard condition is true and executes the statements in that block. It then leaves the conditional statement. If none of the guarded blocks are executed, but an else block exists, then the else block is executed.

In other words, at most one of the blocks of a conditional statement will be executed.

Blocks which contain only one statement may be written with a single colon instead of a pair of curly braces:

let someNumber = random(-1, 1);

if someNumber < 0:
    return "negative";
else if someNumber > 0:
    return "positive";
else:
    return "exactly zero";

Loops

Loops let you repeat blocks of code for each element of a sequence, or until some condition is met.

for loops

To repeat a block of code for each element in a sequence, use a for loop. A for loop consists of an iterator name, a sequence expression and a loop body.

// Example: calculate the total of the numbers 1, 2, and 3.

let numbers = [1, 2, 3];
let total = 0;

for n in numbers {
    set total = total + n;
}

return total;

In the example above, n is the iterator name and numbers is the sequence expression. In plain language, the loop might be understood to say: "for each element in the variable numbers, assign that element to a local variable called n, and then run the statement inside the loop body with n added to the scope".

while loops

To repeat a block of code until some boolean condition is no longer true, use a while loop. A while loop consists of a condition expression and a body. The execution of the body is repeated until the condition is no longer true. If the condition is false in the first place, the loop body is never executed.

// Example: calculate the factorial of the number 7 using a while loop.
let n = 7;
let result = 1;

while n > 0 {
    set result = result * n;
    set n = n - 1;
}

return result;

While loops should be used cautiously. Since the body of a while loop is repeated until the condition expression is false, it follows that each repetition of the body must somehow bring the condition closer to being false. In the example above, each iteration decrements the value of n by one, making sure that the expression n > 0 will eventually be false.

Failure to construct a while loop in such a way that the condition will eventually be false is called an infinite loop. It will stop your application in its tracks.

break

The break statement can be used in both for loops and while loops. It causes the program to immediately stop the current iteration of the loop and perform no more iterations.

// Example: an infinite loop which breaks after three iterations.

let n = 0;
while true {
    if n > 2:
        break;
    set n = n + 1;
}

continue

The continue statement can be used in both for loops and while loops. It causes the program to stop the current iteration of the loop and proceed with the next.

// Example: calculate the sum of the odd numbers between 1 to 10.

let result = 0;

for n in range(1, 10) {
    if n mod 2 == 0:
        continue; // this number is even, so we skip to the next.
    set result = result + n;
}

return result;
PreviousQueriesNextFunction definitions

Last updated 1 year ago

Was this helpful?

⏸️