"Sputnik" help  
Sputnik Help
Unless(<expression>)
{
statements
...
}
Else Unless
(expression-n)
{
else Unless
statements
...
}
Else
{
else statements
...
}

Description

Conditionally run statements.

Parameters

expression If the expression is false, the first statement block is executed. If not, the first false Else Unless block is executed. Otherwise, the "Else" block is executed.

Both the Else Unless and Else blocks are optional.

Remarks

Unless statements may be nested.

You may mix If stuff in with this statement.

The Unless statement in Sputnik provides an alternative way to conditionally execute statements based on the evaluation of one or more expressions. It allows you to handle scenarios where the condition is false, rather than true, as in the case of the If statement.

The Unless block is the primary block where the initial expression is evaluated. If the expression is false, meaning it does not evaluate to true, the statements within the Unless block are executed. If the expression is true, the program moves on to the next block, which is the Else Unless block. This block allows you to evaluate additional expressions and execute statements based on their falsity. The Else Unless block can be repeated multiple times to handle various conditions.

If none of the Unless or Else Unless expressions evaluate to false, the program proceeds to the Else block. The Else block is optional, but when included, its statements are executed if none of the previous conditions were met.

Nested Unless...Else Unless...Else statements are supported, allowing for more complex decision-making logic. You can nest Unless blocks within other Unless blocks to handle specific conditions within a broader context.

The expressions used within the Unless statement can include boolean operators and logical operators to create more complex conditions. Parentheses can be used to group expressions and control the evaluation order.

You can also mix the Unless statement with the If statement to further expand the conditional logic. This allows you to combine conditions based on both true and false evaluations.

The Unless statement in Sputnik offers a flexible and structured approach to handle conditional execution of statements when the condition is false. It allows you to handle different scenarios, make decisions based on falsity, and control the flow of your program. By using this statement, you can create logic that responds dynamically to changing conditions and efficiently directs the execution path of your code.

Related

If, Select

Example

Make sure you have read all and understand all of the If statement before reading this.

This works very similar to an If statement but instead of triggering on true values it triggers on false ones like so:

my $a = 10;
unless ($a == 10)
{
    say "It is not 10";
}
else if ($a == 1) // you can mix if statements in
{
    say "It is 11";
}
else
{
    say "It might be 10";
}
// PRINTS
// It might be 10

Using else unless:

my $a = 10;
unless ($a == 10)
{
    say "It is not 10";
}
else unless ($a == 9)
{
    say "It is not 9";
}
else
{
    say "It might be 10";
}
// PRINTS
// It is not 9

 


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org