END WHILE Instruction

The END WHILE instruction designates the end of a WHILE region.

The WHILE Instruction is only available when you are creating a script in the Component Studio and cannot be used in the template.

At the end of a WHILE region you create using an WHILE instruction, you must add an END WHILE instruction to tell HotDocs where to stop processing.

You must use an END WHILE instruction after a WHILE instruction to close the WHILE region.

Instruction name Model After you drag and drop the model into the script tab:
END WHILE END WHILE You don't need to do anything further with this model.

Example

In the following example, you want to create a list of signers in a will. Since the signers may include both beneficiaries and fiduciaries, you want to merge both lists into one. Because some fiduciaries may also be beneficiaries, you will want to remove any duplicate names. To loop through the list of fiduciaries, you will use the WHILE instruction:

SET Signer Count TO 0

REPEAT Beneficiary Information

INCREMENT Signer Count

SET Signer Name[Signer Count] TO Beneficiary Name

END REPEAT

REPEAT Fiduciary Information

SET Lookup TO 1

WHILE Lookup <= Signer Count AND Fiduciary Name != Signer Name[Lookup]

INCREMENT Lookup

END WHILE

IF Lookup > Signer Count

INCREMENT Signer Count

SET Signer Name[Signer Count] TO Fiduciary Name

END IF

END REPEAT

In the first part of this script, the Beneficiary Information dialog is repeated, and as answers are entered, their values are set to be used for Signer Name (which is the variable that will be repeated to insert all the names of the signers). Then, in the second part of the script, as the Fiduciary Information dialog is repeated, HotDocs uses the WHILE expression to test whether the name of the fiduciary is the same as any of the beneficiary names. If it is not, it will likewise be added to the Signer Information dialog. (When you insert the REPEAT instruction for the Signer Information dialog in the template, clear the Ask Automatically option at the Dialog Editor (Options tab). See Control Whether Dialogs are Asked Automatically for details.)

In the next example, you need to remove unwanted space characters from a user's account number. Here, the WHILE instruction is used to repeat an answer, character by character, so that HotDocs can check to see if there are space characters in the answer. If there are, HotDocs removes them and rewrites the answer.

SET Count Index TO 1

WHILE Count Index <= LENGTH( Account Number )

IF MID(Account Number, Count Index, 1 ) = " "

SET Account Number TO FIRST( Account Number, Count Index -1 ) + LAST( Account Number, LENGTH(Account Number) - Count Index)

ELSE

INCREMENT Count Index

END IF

END WHILE

This script uses a temporary counter (Count Index) to keep track of which character in the answer HotDocs is looking at. Any time the answer is repeated and HotDocs finds a space character, it removes it by concatenating the characters before and after the space character. HotDocs then makes sure that the new character it is now examining isn't a space character either. If it is not, HotDocs increments the temporary counter, moves to the next character, and repeats this process.

Download

After you download the example template, you can import the template to any workspace to see this example code in action.