To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Official ZPE/YASS documentationWhile loops

A while loop will loop while a condition is true.

YASS
while($a < 10)
  //Do something
end while
  

A common form of while loop is the while-true loop. This loop will continue indefinitely since there is no condition from which it will stop. It can be broken by a return or break command, however.

YASS
while(true)
  //Do something
end while
        

As with all loops, while loops may be terminated by end loop.

YASS
while($a < 10)
  //Do something
end loop
  

Do while loops

Version 1.5.1 added do while loops. These loops are incredibly simple to use and work exactly as a standard while loop does except with one subtle difference. A while loop may not necessarily execute a statement:

YASS
$a = 0
while($a > 10)
  //Do something
end loop
  

With a do while loop it is guaranteed to execute at least once. Many other languages out there also implement a do while loop that works similarly. Below is an example of a do while loop in YASS:

YASS
$a = 0
do
  //Do something
loop while($a > 10)
  

Loop until

Another form of loop, similar in syntax to the while loop, is loop until. This loop will loop while a condition is false or until a condition is true.

YASS
$a = 0
loop until($a > 10)
  //Do something
end loop
  

One of the first programs I ever wrote was in Visual Basic 6 and was a guess the number game. It took several lines of code to write. With ZPE this can be done very easily.

YASS
$n = random_number(1, 20)
while(value(input("Please insert a number between 1 and 20.")) != $n)
  print("Sorry, wrong answer. Guess again.")
end while
print("Correct. The number I was thinking of was " & $n & ".")
  
Comments
Code previewClose
Feedback 👍
Comments are sent via email to me.