Basic - Loop with condition on the beginning: do while loop, 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.

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:
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

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 wend

Description

while condition
statements
 wend
Used keywords: while wend

Input

Note: Here usable statements:
break statement continue statement
Compatible programing languages:
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
Languages: en hu cz sk