Chaga Programming Language: Chapter 4: Selection Statements

IF statement

Usage:

  • if (expression) {statement block}

Example 1: if statement

if (TRUE)
{
  if (TRUE or FALSE)
  {
    call print ("This statement block is executed by the nested IF statements.\n");
  }
}

Output from example 1

This statement block is executed by the nested IF statements.

IF-ELSE statement

Usage:

  • if (expression) {statement block} else {statement block}

Example 2: if-else statement

if (TRUE)
{
  if (TRUE and FALSE)
  {
    call print ("Statement block one is executed.\n");
  }
  else
  {
    call print ("Statement block two is executed.\n");
  }
}
else
{
  call print ("Statement block three is executed.\n");
}

Output from example 2

Statement block two is executed.

SWITCH statement

Usage:

  • switch (expression) {case constant: statement block break; case constant: statement block break; case constant: statement block break; ... default: statement block break;}
  • switch (expression) {case constant: statement block case constant: statement block case constant: statement block break; ... default: statement block break;}

Example 1: switch statement

switch (counter)
{
  case 1:
  break;
  case 2:
  break;
  case 3:
  break;
  default:
  break;
}

BREAK statement

Usage:

  • The break statement is used to prematurely leave an iterative loop (e.g. do, for, while) or a switch statement.
  • break;

Copyright © 2025, 2026 Robert James Bruce.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is available at https://www.gnu.org/licenses/fdl-1.3.html