While Loop

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "= While...WEnd = === Description === Loop based on an expression. <pre> While <expression> statements ... WEnd </pre> === Parameters === ==== expression ==== If th...")
 
m (1 revision)
 
(8 intermediate revisions by one user not shown)
Line 1: Line 1:
= While...WEnd =
+
= While =
  
 
=== Description ===
 
=== Description ===
Line 6: Line 6:
  
 
<pre>
 
<pre>
While <expression>
+
While ( <expression> )
 +
{
 
     statements
 
     statements
 
     ...
 
     ...
WEnd
+
}
 +
</pre>
 +
 
 +
<pre>
 +
While ( )
 +
{
 +
    statements
 +
    ...
 +
}
 
</pre>
 
</pre>
  
Line 16: Line 25:
 
==== expression  ====
 
==== expression  ====
  
If the expression is true the following statements up to the WEnd statement are executed. This loop continues until the expression is false.
+
If the expression is true the following statements are executed. This loop continues until the expression is false.
 +
 
 +
You can omit the expression to cause an INFINITE loop however make sure to have a break somewhere...
  
 
=== Remarks ===
 
=== Remarks ===
  
While...WEnd statements may be nested.
+
While statements may be nested.
  
 
The expression is tested before the loop is executed so the loop will be executed zero or more times.
 
The expression is tested before the loop is executed so the loop will be executed zero or more times.
  
To create an infinite loop, you can use a non-zero number as the expression such as "While True"
+
To create an infinite loop, you can use a non-zero number as the expression such as "While (True)"
 +
 
 +
The expression can contain the boolean operators of &&, ||, ! as well as the logical operators <, <=, >, >=, ==, !=, <>, eq, eqi, neq and neqi as needed grouped with parentheses as needed.
  
 
=== Example ===
 
=== Example ===
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
While $i < 20
+
$i = 0;
println( "Value is: " . $i )
+
While ( $i < 20 )
$i++
+
{
WEnd
+
println( "Value is: " . $i );
 +
$i++;
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
Reverse While
 +
 +
<syntaxhighlight lang="sputnik">
 +
my $i = 0;
 +
println("Value $i {\$i++!}") while($i < 10);
 +
</syntaxhighlight>
 +
 +
A while loop can run forever and ever (until a BREAK is called) by omitting the expression
 +
 +
<syntaxhighlight lang="sputnik">
 +
$i = 0;
 +
While ( )
 +
{
 +
println( "Value is: " . $i );
 +
$i++;
 +
}
 +
</syntaxhighlight>
 +
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:38, 14 June 2015

Contents

While

Description

Loop based on an expression.

While ( <expression> )
{
    statements
    ...
}
While ( )
{
    statements
    ...
}

Parameters

expression

If the expression is true the following statements are executed. This loop continues until the expression is false.

You can omit the expression to cause an INFINITE loop however make sure to have a break somewhere...

Remarks

While statements may be nested.

The expression is tested before the loop is executed so the loop will be executed zero or more times.

To create an infinite loop, you can use a non-zero number as the expression such as "While (True)"

The expression can contain the boolean operators of &&, ||, ! as well as the logical operators <, <=, >, >=, ==, !=, <>, eq, eqi, neq and neqi as needed grouped with parentheses as needed.

Example

$i = 0;
While ( $i < 20 )
{
	println( "Value is: " . $i );
	$i++;
}

Reverse While

my $i = 0;
println("Value $i {\$i++!}") while($i < 10);

A while loop can run forever and ever (until a BREAK is called) by omitting the expression

$i = 0;
While ( )
{
	println( "Value is: " . $i );
	$i++;
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox