Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Repetitive actions in the routing section > Repeat while a condition is true
Repeat while a condition is true
The While...End While block is an alternative to Do...While for repeating a set of statements all the time that an expression is True.
While Expression
End While
A logical expression that controls whether the statements in the loop will be repeated.
The statements to be executed.
This example shows how to use While to ask a question and repeat it if the answer is not correct. The questions in the metadata section are:
HoursTV "How many hours, to the nearest quarter hour, did you
    spend watching TV last week?" double [0 .. 168];
Programs "How much of that time was spent watching ..." loop
News "News programs",
Sitcoms "Situation comedies",
Otherprogs "Other programs"
} fields
ProgTime "" double [0..168];
) expand grid;
NoMatch "The sum of the times you have just entered is {Total}     but the total time you gave earlier is {HoursTV}. Please
    check those figures."
The routing section needs to do three things:
1 Ask the question.
2 Check that the sum of program times matches the total time.
3 If the sum of times does not match the total time, issue an error message and repeat the question.
The loop that you write is as follows:
Dim Total2, Prog2
While (Total2 <> HoursTV)
' Add up the individual program times
For Each Prog2 in Programs
Total2 = Total2 + Prog2.Item["ProgTime"]
' Compare sum of program times with original total time
If Total2 <> HoursTV Then
NoMatch.Label.Inserts["Total"] = Total2
NoMatch.Label.Inserts["HoursTV"] = HoursTV
End If
End While
You can also write this example using Do or For...Next. See Repeat while or until a condition is true and A set number of repetitions for details.
See also
Repetitive actions in the routing section