FANDOM


16px-Pencil

The while loop is the most general type of loop, essentially a continuing if statement; it will execute while its Boolean expression (or "condition") is true. An infinite loop occurs when the condition never evaluates to false.

For more information see the Wikipedia article.

Examples of while loopsEdit

Curly bracket programming languages Edit

int x = 0;
int y = 10;

  while(x < y){
    x++;
  }

Language: Pascal Edit

while (x < y) do
begin
   {Do something.}
end;

PHPEdit

$i=0;

while ($i<10) {
	// do something
	$i++;
}

Or:

while (true) {
	// do something
	if ($a==$b)
		break;
}

Visual BasicEdit

Do While x < y
    ' Do something
Loop

Or:

While x < y
    ' Do something
End While

See Also Edit

Control structures
If statement - Switch statement - While loop - For loop - Foreach loop - Do while loop