"Sputnik" help  
Sputnik Help
forever (<condition>)
{
statements
...
}

Description

Creates an infinite loop that continues indefinitely or until the specified condition becomes false.

Parameters

<condition> An optional condition that determines whether to start the loop. If the condition is not specified or evaluates to true, the loop will start. If the condition is false, the loop will be skipped.

Remarks

Forever statements may be nested.

The Forever loop is a control structure that allows you to create an infinite loop in Sputnik. It can be used when you want to repeat a block of code indefinitely or until a specific condition is no longer true.

If the <condition> is provided, it will be evaluated only once at the start of the loop. If the condition evaluates to true, the loop will begin executing the code block. If the condition evaluates to false, the loop will be skipped, and the program will continue executing the next statement after the loop.

If the <condition> is not specified (i.e., an empty parentheses ()), the loop will start immediately.

Related

Loop Statements
Continue Statement
Redo Statement
Break Statement

Example

Basic Example:

my $a = 10;

forever($a == 10)
{
    say "Cat! $a";
    $a++;
    if ($a == 20)
        break;
}

// PRINTS
// Cat! 10
// Cat! 11
// Cat! 12
// Cat! 13
// Cat! 14
// Cat! 15
// Cat! 16
// Cat! 17
// Cat! 18
// Cat! 19

Notice how it ignores the condition after first check? This is what makes the Forever loop interesting.

If we ignore any condition check it will loop forever like so:

my $a = 0;

forever()
{
    say "Cat! $a";
    $a++;
    if ($a == 7)
        break;
}

// PRINTS
// Cat! 0
// Cat! 1
// Cat! 2
// Cat! 3
// Cat! 4
// Cat! 5
// Cat! 6
This time it would loop forever and has no initial condition check.

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