LogoLogo
About
  • Home
  • Guides
  • BDK
  • REST API
  • Release Notes
  • Getting Started
    • What is Kognitos?
    • Logging In
    • Account Setup
    • Quick Start Guide
    • Core Concepts
  • Writing Automations
    • Automation Basics
      • Defining Data
      • Comments
      • Conditionals
      • Keywords
      • Loops
    • Calling Other Processes
      • Calling A Subprocess
      • Invoking a Subprocess
      • Starting Parallel Runs
    • Validating Data
    • Context Based Learning
    • Using the Debugger
  • Books
  • Automation Management
    • Scheduled Processes
    • Email Triggers
  • Enterprise Dashboard
  • Exception Handling
    • Providing Guidance
    • Resolving Common Exceptions
    • Learnings
  • Account Management
    • API Keys
    • User Roles & Permissions
Powered by GitBook
On this page
  • Overview
  • General Syntax
  • Looping with a Counter

Was this helpful?

Export as PDF
  1. Writing Automations
  2. Automation Basics

Loops

Learn about writing loops in Kognitos to repeat actions for multiple items.

Overview

A loop allows you to repeat actions for multiple items. In Kognitos, you can create a loop using process each x as follows, where x represents the item in a set. Loops are especially useful for batch processing, where you need to handle multiple items in a consistent manner.

General Syntax

To start a loop, use the following syntax:

process each {item} as follows
  {actions to perform on each item}

By indenting the lines after process each {item} as follows, Kognitos will know which instructions to follow for each item.

Indentation is Key

Remembering to indent when looping through objects in your automation is very important!

Example

process each document as follows
  get the document's invoice number
  get the document's fields

Looping with a Counter

To track the number of iterations in a loop, you can use a counter. A counter is a numeric data element that starts at an initial value (usually zero) and increments with each iteration of the loop. This allows you to keep track of how many times the loop has executed.

Syntax

Initialize the counter before starting the loop. Within each iteration, increment the counter by 1.

the counter is 0
process each {item} as follows
	{actions to perform on each item}
	add 1 to the counter

Example

In this example, a loop is used to iterate through each page in a document. The counter is incremented after each page is processed.

the counter is 0
process each page as follows
  get the page's invoice number
  get the page's booking reference
  add 1 to the counter

Last updated 1 month ago

Was this helpful?