Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
We've encountered an issue exporting this macro. Please try exporting this page again later.
Excerpt

Statements provide a convenient method to execute conditional or repetitive operations. The syntax is C/C++/Java like, so things should be easy to grasp.

If-Else Statement

The if-else statement offers support for conditionally executing operations.

Syntax

The general syntax for this is:

...

Button handy
blanktrue
color#0052CC
nameSend Feedback
linkhttps://docs.google.com/forms/d/e/1FAIpQLScmToBe3vynAlb5fdKwCGxYqnTbDc66sIBgeecG2BuFDuHc7g/viewform?entry.2002826954=Statements+-+15488140
widthauto

Info

This page covers syntax, usage patterns, and practical examples for each statement type used in Simple Issue Language (SIL™).

Excerpt

Statements in SIL provide a convenient method to create conditional logic (if-else, switch) and repetitive operations (for, while, do-while) with a syntax similar to C, C++, and Java.

Statements enable Power Suite users to create sophisticated script logic while maintaining code readability.

For each statement, you’ll find a description of its usage in SIL, syntax, and examples

If-else statement

The if-else statement enables conditional execution of code blocks, allowing you to create branching logic based on specific conditions.

Contents:

Table of Contents
minLevel1
maxLevel2
outlinefalse
styledefault
typelist
printabletrue

Syntax

Code Block
if (condition) {
    Instruction1;
    ...          //Instructions when condition is true
    InstructionN;
} else if {
    Instruction1:
    ...          //Instructions when condition is true
    InstructionN;
} else {
    Instruction1:
    ...          //Instructions when both condition are false
    InstructionN;
}
NoteNote: the

The else branch can be omitted.

Example

Basic if-else example

Code Block
if
(isNotNull(fixVersions) and affectedVersions
(issueType == "Bug" && environment == "Production") {
"1.1"}

    priority = "Highest";
} else if {issueType == "Bug" && environment == "Development") {
    
affectedVersions
priority = "Medium";
} else {
"1.1", "1.0" , "1.2"}; fixVersions = {"1.2" , "1.2" , "1.3"}

    priority = "Low";
}

Example description

This example checks the following conditions in a Jira issue:

  • If the issue type is a Bug and the environment is Production, the issue receives Highest priority.

  • If the conditions are not met (else), the check continues with the second set of conditions.

  • If the issue type is a Bug and the environment is Development, the issue receives Medium priority.

  • If this second condition is not met either (else), issues for all other combinations are set to Low priority.

Complex if-else example

Code Block
if (issueType == "Bug" && severity == "Critical" && impactedUsers > 100) {
    priority = "Highest";
    assignToTeam = "ProductionSupport";
    notifyStakeholders = true;
} else if ((issueType == "Bug" && severity == "Major") || 
           (issueType == "Security" && environment == "Production")) {
    priority = "High";
    assignToTeam = "DevelopmentTeam";
    notifyStakeholders = impactedUsers > 50;
} else if (issueType == "Enhancement" && businessValue == "High" && 
           implementationEffort == "Low") {
    priority = "Medium";
    assignToTeam = "DevelopmentTeam";
    notifyStakeholders = false;
} else {
    
affectedVersions
priority = 
{
"
1.1
Low"
}
;
    
fixVersions
assignToTeam = 
{
"
1.0"}; }For Statement
Backlog";
    notifyStakeholders = false;
}

Example description 

This example code implements a comprehensive issue triage system that:

  • Sets Highest priority for critical bugs affecting many users.

  • Assigns High priority to major bugs and production security issues.

  • Prioritizes high-value, low-effort enhancements as Medium.

  • Routes issues to appropriate teams and manages stakeholder notifications.

  • Defaults all other cases to Low priority in the backlog.


For statement

The for statement provides a compact way to iterate over a range of values.

Programmers

It is often

refer

referred to

it

as the for loop statement,because it repeatedly loops until a particular condition is satisfied. 

tip

In SIL, the for statement

has

provides two

forms

primary iteration methods:

the
  • standard

for or
  • form: simply for

form
the
  • foreach form

The

Standard

FormSimilar to C, C++ or Java of the for statement can be expressed as follows:

form

Syntax

Code Block
for(<init>; <condition>; <increment>){
   Instruction1;
   ...
   InstructionN;
}
note

For

this first

the standard form, the <init> can be an attribution of an already defined variable or a definition for a new variable.

The For Each Form

The for each form can be expressed as follows:

Code Block
for(<variable_definition> in #{array}){
   Instruction1;
   ...
   InstructionN;
}

Examples 

Example 1 (standard form)

Prints the numbers from 0 to 9*

Code Block
for(number i = 0; i < 10; i = i + 1){
   print(i);
}

Example 2 (foreach form)

Prints the list of the watchers of a specific issue*

Example

Code Block
// Prints numbers from 0 to 9 in console
for (number i = 0; i < 10; i++) {
    runnerLog(i);
}

Example description

This example demonstrates a basic iteration:

  • Initializes a counter i to 0.

  • Continues looping while i is less than 10.

  • Increments i by 1 in each iteration.

  • Prints each number from 0 to 9 (total 10 numbers) in the SIL Manager output console.

Foreach form

Syntax

Code Block
for(<variable_definition> in <array>){
   Instruction1;
   ...
   InstructionN;
}

Example

Code Block
for(string user in watchers){
   
print
runnerLog(user);
}

Example description

While Statement 

This foreach loop iterates through a collection of watchers of a specific issue and prints the list of the watchers:

  • Automatically iterates through each element in the watchers array.

  • Assigns each element to the user variable in each iteration.

  • Prints the name of each watcher in the SIL Manager output console.


While statement 

The while statement

offers

provides support for

repeated executions. This form

conditional repetitive execution of a code block. It evaluates the condition first

and then executes

:

  • If the condition is true, the instructions in the body (the loop) is executed.

  • If the condition is false from the start, the loop body is never executed.

Note

When using the while statement in your scripts, make sure to include safeguards against infinite loops. Infinite loops can freeze your program, consume system resources, and potentially crash your application.

Syntax

Code Block
while(condition) {
    Instruction1;
    ...                // Instructions when condition is true
    InstructionN;
}

Example

Code Block
string [] multisel;
number i = 1;
while(i <= 3) {
    multisel += 
arrayAddElement(multisel,
"value" + i
)
;
    i
= i + 1
++;
}
Do-While Statement

Example description

This while loop in this example demonstrates how to build a collection incrementally:

  • Starts with i as 1.

  • Continues looping while i is less than or equal to 3.

  • In each iteration, adds a new element to multisel array

  • Element is created by concatenating "value" with the current value of i.

  • After completion, multisel will contain ["value1", "value2", "value"].


Do-while statement

The do-while statement is similar to the while statement

, except the condition is evaluated after the execution of the encapsulated block. So,even

except that it guarantees at least one execution of its code block before evaluating the termination condition. Even if the condition is false, the instructions will still be evaluated once.

Note

Syntax

The general syntax:

When using the while statement in your scripts, make sure the condition can be met within the loop body.

Syntax

Code Block
do {
    Instruction1;
    ...
    InstructionN;
} while(condition);

Example

Code Block
number i = 1;
string [] people;
do {
    people += watchers[i];
    i
= i + 1
++;
} while(i < 5);

Example description

This example do-while loop populates a people array, ensuring at least one processing of the loop body:

  • Starts with i as 1.

  • Adds watchers to the people array from index 1.

Switch Statement
  • Increments i after each iteration.

  • Continues until i is no longer less than 5.


Switch statement

The switch statement

offers support for executing different operations depending

provides a structured mechanism for conditional execution based on the value of a specific variable.

The variable can be either a number or a string

  • It accepts both number and string variables.

  • Evaluates the input variable against multiple predefined case values.

  • Executes the first matching case's code block.

  • Continues executing subsequent cases unless a break statement is used.

  • Supports specific handling for unmatched cases through the default branch.

Syntax

The general syntax:

Note:
Code Block
switch(variable) {
    case value1:
		Instruction11;
		...
		Instruction1N;	
	[break;] 
    case value2:
		Instruction21;
		...
		Instruction2N;
	[break;]
	...
	case valueN:
		InstructionM1;
		...
		InstructionMN;
	[break;]
	[default:
		InstructionDef1;
		...
		InstructionDefN;]
}
Note

The break statements and the default branch can be omitted

as well as the break statements.Example

, which changes the script behavior.

Example 1: Switch with numbers (with break statements and default branch)

Code Block
switch (priority) {    // priority is a number variable
    case 1:
        // Executes only when priority equals 1
        escalateImmediately();
        break;         // Prevents fallthrough to case 2
    case 2:
        // Executes only when priority equals 2
        scheduleReview();
        break;         // Prevents fallthrough to case 3
    case 3:
        // Executes only when priority equals 3
        addToBacklog();
        break;         // Prevents fallthrough to default
    default:
        // Executes when priority doesn't match 1, 2, or 3
        logInvalidPriority();
}

Example 2: Switch with string matching

Code Block
switch (
season
status) {      // status is a string variable
    case "
Summer
ERROR":
        
print("It's too hot!"
logError();    // No break - falls through to "WARN"
    case "WARN":
        sendAlert();
        break;         // Stops here for both "ERROR" and "WARN"
    case "
Winter
INFO":
        
print("It's too cold!"
logMessage();
        break;
    default:
        // Handles any status value not matching above cases
      
print("It's
 
just
 
fine!"
logUnknownStatus();
}

Break Statement

The break statement can be used in the following situations:

  • inside a loop (for, while): when encountering the break, the execution of the loop is terminated and the control is transferred to the statement that follows the loop;

  • in switch statements: when a case is followed by a break, it does not execute subsequent cases and control is transferred out of the switch statement.

Example

Code Block

Examples description

In both examples, cases are evaluated from top to bottom. Only equal values trigger case execution.

  • The break statement terminates the switch block's execution after a case is handled, preventing unintended fallthrough to subsequent cases. The second example demonstrates an intentional fallthrough. For additional information about the break statement, refer to the Break statement section.

  • The default branch functions as an essential catch-all mechanism within the switch statement. It executes when the input value doesn't match any of the defined case values, providing a way to handle unexpected or unspecified inputs. While optional, including a default branch is considered best practice as it ensures comprehensive handling of all possible input values and helps prevent undefined behavior.


Break statement

The break statement serves two distinct control flow purposes:

  • Loop termination: When used within loops (for, while, do-while), the break statement provides immediate termination of the entire loop execution, transferring control to the first statement following the loop block. This enables early exit from loops based on specific conditions.

  • Switch exit: Within switch statements, break statements terminate the switch block execution, preventing fallthrough to subsequent cases and transferring control to the code following the switch structure.

Example

Code Block
// Prints numbers 0-4 in the console, then exits loop early
for (number i = 0; i < 10; i
= i + 1
++) {
   if (i >= 5) {
      break;  // Terminates loop when i reaches 5
   }
   
print
runnerLog(i);  // Only prints 0,1,2,3,4
}
// Execution continues here after break

Continue

Statement

statement

The 

continue statement

continue statement is used inside a loop (for, while)

causing it to jump to the next iteration, skipping the execution of the rest of the statements inside the loop for the current

. It provides a mechanism to skip the remaining code within the current loop iteration, immediately jumping to the loop’s next iteration.

Example

Code Block
number i = 1;
while (i <= 10) {
    
if (i % 3 == 0) {
i = i + 1; continue; } print(i); i = i + 1; }
        i++;        // Update counter before continue
        continue;         // Skip printing multiples of 3
    }
    runnerLog(i);            // Prints: 1,2,4,5,7,8,10
    i++;
}

Best practices for using statements in SIL

Following some simple best practices can prevent common pitfalls and ensure your code is maintainable, reliable, and efficient.

General

  • Keep statement blocks concise and focused.

  • Avoid mixing too many different control structures.

  • Use meaningful variable names that indicate purpose.

  • Add comments for complex logic or business rules.

  • Test thoroughly.

  • Include appropriate error-handling mechanisms. For example, validate inputs before processing, log or report errors.

  • Keep your code well-organized by grouping related control structures.

  • Maintain consistent indentation and formatting.

  • Document complex control flow patterns.

If-else statements

  • Keep conditions simple and readable.

  • For multiple conditions, consider using switch statements instead.

  • Avoid deeply-nested if statements (maximum 3-4 levels).

  • Consider extracting complex conditions into separate boolean functions.

Switch statements

  • Always include a default case for error handling.

  • Use break statements consistently to prevent unintended fallthrough.

  • Document intentional fallthrough cases with comments.

  • Consider switch instead of if-else when comparing a single variable against multiple values.

For loops

  • When the iteration count is known, use the standard form for loops.

  • When processing arrays, preferably use for each loops.

  • Initialize variables properly before the loop.

  • Avoid modifying loop variables inside the loop body.

While loops

  • Include safeguards against infinite loops.

  • Ensure loop conditions can eventually become false.

  • Initialize all variables before the loop.

  • Validate loop variables have been properly updated.

  • Use while when iteration count is unknown.

  • Add timeout conditions for time-sensitive operations.

Do-while loops

  • Use when code must execute at least once. Best suited for validation scenarios.

  • Keep the loop body focused on a single task.

  • Ensure the condition can be met within the loop body.

Break statements

  • Use to exit loops early when a condition is met.

  • Avoid using multiple breaks in a single loop.

  • Document the exit condition clearly.

  • Consider extracting complex logic into separate functions.

Continue statement

  • Use to skip iterations based on specific conditions.

  • Place continue statements early in the loop body.

  • Avoid multiple continue statements in a single loop.

  • Ensure all necessary variables are updated before continue.


See also

Contents

toc