Flow control is a core concept in programming and is just as important in conversational AI. In Colang 2.0, flow control enables your bot to make decisions and repeat actions, resulting in more natural and dynamic conversations. In this lesson, you'll learn how to use conditionals, event branching, and loops to create advanced conversational flows.
Keyword: if
, elif
, else
Conditional branching lets your bot choose different actions based on the current state or user input. The syntax is similar to Python, making it easy to use for those familiar with traditional programming.
Example: Handling Subscription Status
Here, the bot checks the user's subscription status and responds accordingly.
Keyword: when
, or when
, else
Event branching allows your bot to react to multiple possible events, starting them concurrently and responding to whichever happens first.
Example: Handling Multiple Events
This pattern is useful when the bot should be ready to handle several different user intents at the same time.
If you don't include an or when
or else
branch, you can use an await
or match
statement instead of the when
construct.
This is functionally similar to:
But since there are no additional branches, match
is a simpler alternative.
Keyword: while
, break
, continue
Loops let your bot repeat actions until a condition is met, which is useful for tasks like collecting information or confirming details.
Example: Collecting Multiple Email Addresses
This flow keeps asking the user for email addresses until they type "done".
break
: Exit a loop early.continue
: Skip to the next iteration of a loop.return
: Finish a flow and optionally return a value.abort
: Fail a flow immediately.pass
: Do nothing; useful as a placeholder.
Example: Validating User Input in a Loop
In this lesson, you learned how to use Colang 2.0's flow control features—conditionals, event branching, and loops—to create flexible and responsive conversational experiences. These tools allow your bot to make decisions and repeat actions, all of which are essential for building advanced chatbots.
Next, you'll get hands-on practice applying these concepts to real-world scenarios.
