Loop with condition on the beginning: while, while end while, do while loop, while do, while wend

Condition testing is done at the beginning of the loop. before each iteration the condition is tested, if it is was true. before the first iteration is a condition test, the use of this loop is excellent in situations where perhaps we don't need to execute the cycle.

while

Description

while (condition) statement
Used keywords: while

Input

Note: Here usable statements:
break statement continue statement
Compatible programing languages:
C | Visual C++ .NET | C++ | C# | Java | JavaScript | PHP

Examples

Example

Loop with condition on the beginning the possible of use:
i=0;
while (i<10) ++i;
x =0;
while (i<20)
{
 i= i+2;
 if (i==16)
 {
    continue;
 }
 x++; 
}

Example

Other pieces of example codes:
while (i>0)
   if (i==10)
     break;
   else 
   {
     i--;
   }
while (y>1)
{
  x++;
  y--;
}
if ( x >= 12 )
   while ( y >= 0 )  
      --y;
while ( y <= 32 )  
   y++;

while end while

Description

while condition
statements
end while
Used keywords: while end

Input

Note: Here usable statements:
break statement continue statement
Compatible programing languages:
Visual Basic .NET

Examples

Visual Basic .NET

Loop with condition on the beginning the possible of use:
i=0
while i<10
 i=i+1
end while
x =0
while i<20
 i= i+2
 if i=16 then
    continue while
 end if
 x=x+1 
end while

Visual Basic .NET

Other pieces of example codes:
while i>0
   if i=10 then
     exit do
   else
     i=i-1
   end if
end while
if  x >= 12 then
   while  y >= 0   
      y=y-1
end while
end if
while  y <= 32   
   y=y+1
end while

do while loop

Description

do while condition
statements
loop
Used keywords: do while loop

Input

Note: Here usable statements:
break statement continue statement
Compatible programing languages:
Basic | FreeBASIC | Visual Basic .NET

Examples

Basic

Loop with condition on the beginning the possible of use:
i=0
do while i<10
 i=i+1
loop
x =0
do while i<20
 i= i+2
 if i=16 then
    continue while
 end if
 x=x+1 
loop

Basic

Other pieces of example codes:
do while i>0
   if i=10 then
     exit do
   else
     i=i-1
   end if
loop
if  x >= 12 then
   do while y >= 0   
      y=y-1
loop
end if
do while y <= 32   
   y=y+1
loop

while do

Description

while condition do statement;
Used keywords: do while

Input

Note: Here usable statements:
break statement continue statement
Compatible programing languages:
Pascal | Object Pascal | Free Pascal

Examples

Object Pascal

Loop with condition on the beginning the possible of use:
i:=0;
while i<10 do inc(i);
x :=0;
while i<20 do
begin
 i:= i+2;
 if i=16 then
 begin
    continue
 end;
 inc(x); 
end;

Object Pascal

Other pieces of example codes:
while i>0 do
   if i=10 then
     break
   else 
   begin
     dec(i)
   end;
while y>1 do
begin
  inc(x);
  dec(y);
end;
if  x >= 12 then
   while  y >= 0 do  
      dec(y);
while  y <= 32 do  
   inc(y);

while wend

Description

while condition
statements
 wend
Used keywords: while wend

Input

Note: Here usable statements:
break statement continue statement
Compatible programing languages:
Basic | FreeBASIC

Examples

Basic

Loop with condition on the beginning the possible of use:
i=0
do while i<10
 i=i+1
loop
x =0
do while i<20
 i= i+2
 if i=16 then
    continue while
 end if
 x=x+1 
loop
Loop with condition on the beginning in another programming language:
Languages: en hu cz sk