While loop

From CodeCodex

Revision as of 14:23, 3 July 2010 by 211.2.129.92 (Talk)

The while loop is a common looping mechanism. It is comparable to the for loop.

Implementations

C / C++

int x = 0;
int y = 10;

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

Java

int x = 0;
int y = 10;

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

Pascal

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

PHP

$i=0;

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

Or:

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

Ruby

x = 10
while x > 0
  # do something
  x -= 1
end

Visual Basic

Do While x < y
    ' Do something
Loop

Or:

While x < y
    ' Do something
End While