"Sputnik" help  
Sputnik Help
Do
{
statements
...
} While (<condition>);

Description

Unlike for, while and until loops, which test the loop condition at the top of the loop, the do...while loop checks its condition at the bottom of the loop.

A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.

Parameters

<condition>

The condition is evaluated just like an If statement. If it is true, the body of the loop is executed again. If it is false, the body of the loop does not execute again (it is guaranteed to execute the body once regardless if the condition is true or not) and flow of control jumps to the next statement just after the for loop.

Remarks

Do...While statements may be nested.

The Do...While loop in Sputnik is a control structure that allows you to repeatedly execute a block of code at least once, and then continue execution as long as a specified condition remains true. It is also known as the repeat...until loop in some programming languages.

In the Do...While loop, the code block is executed first, and then the condition is evaluated. If the condition is true, the loop continues executing the code block. The loop terminates when the condition becomes false.

Related

Loop Statements
Continue Statement
Redo Statement
Break Statement

Example

Basic Example:

// Local variable declaration:
my $a = 10;
// do loop execution
Do
{
   say "value of a: $a";
   $a = $a + 1;
} While($a < 20);
// PRINTS
// value of a: 10
// value of a: 11
// value of a: 12
// value of a: 13
// value of a: 14
// value of a: 15
// value of a: 16
// value of a: 17
// value of a: 18
// value of a: 19

As we see here the code always executes once:

my $a = 1;
Do
{
   say "value of a: $a";
} While($a == 0);
// PRINTS
// value of a: 1

 


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