15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Creating Subprograms and Functions 601<br />

The DO-UNTIL loop repeats until a certain condition becomes True. The<br />

DO-WHILE loop repeats while a certain condition remains True. The two<br />

variations of the DO-UNTIL loop look like this:<br />

Book VI<br />

Chapter 5<br />

DO UNTIL condition<br />

Command<br />

Loop<br />

In this version, the DO-UNTIL loop checks if a condition is True. If so, this<br />

loop never runs. If not, this loop runs at least once. The second variation of<br />

the DO-UNTIL loop looks like this:<br />

Visual Basic and<br />

REALbasic<br />

DO<br />

Command<br />

Loop UNTIL condition<br />

This loop runs at least once be<strong>for</strong>e checking a condition. If the condition is<br />

True, the loop stops. The DO-WHILE loops work nearly identically. If you<br />

want to make a loop that may run zero or more times, you’d use this DO-<br />

WHILE loop:<br />

DO WHILE condition<br />

Command<br />

Loop<br />

If you want a DO-WHILE loop that runs at least once, you’d use this variation:<br />

DO<br />

Command<br />

Loop WHILE condition<br />

Although REALbasic lacks the DO-WHILE loop, it does offer a WHILE-WEND<br />

loop, which looks like this:<br />

WHILE condition<br />

Command<br />

WEND<br />

Creating Subprograms and Functions<br />

You can create a subprogram (or a procedure) by using the SUB keyword as<br />

follows:<br />

SUB Name (Parameter list)<br />

Command<br />

END SUB

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!