Xbasic

WHILE ... END WHILE, EXIT WHILE

Syntax

WHILE Logical_Expression statements EXIT WHILE END WHILE WHILE Logical_Expression statements EXIT WHILE WEND

Arguments

Logical_Expression

An expression that evaluates to .T. (TRUE) or .F. (FALSE).

Description

Repeats the statements it contains while the Logical Expression evaluates to TRUE

Discussion

WHILE ... END WHILE is a control structure that repeats the statements it contains while the Logical Expression evaluates to TRUE. Execution resumes at the line following the end while statement when the Logical Expression is FALSE or when the EXIT while statement is encountered.

Example

This script searches a SQL::ResultSet for the customer record with customer ID "BOLID".

dim search_name as C = "BOLID"
dim cn as SQL::Connection
dim select as C = "SELECT * FROM Customers"

IF (cn.open("::Name::AADemo-Northwind") <> .t.) THEN
    cr = cn.callResult
    ui_msg_box("Error opening connection", cr.text)
    END
end if

IF (cn.execute(select) <> .t.) THEN
    cr = cn.callResult
    ui_msg_box("Error executing query", cr.text)
    cn.close()
    END
end if

while cn.resultSet.nextRow()
    if (alltrim(cn.resultSet.data("CustomerID")) = search_name) then
        lFound = .t.
        exit while
    end if
end while

cn.close()

if lFound
    ui_msg_box("Search", search_name + " has been found.")
else
    ui_msg_box("Search", "Not Found.")
end if

See Also