A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/queries/take-while-clause below:

Take While Clause - Visual Basic

Take While Clause (Visual Basic)

In this article

Includes elements in a collection as long as a specified condition is true and bypasses the remaining elements.

Syntax
Take While expression  
Parts Term Definition expression Required. An expression that represents a condition to test elements for. The expression must return a Boolean value or a functional equivalent, such as an Integer to be evaluated as a Boolean.

The Take While clause includes elements from the start of a query result until the supplied expression returns false. After the expression returns false, the query will bypass all remaining elements. The expression is ignored for the remaining results.

The Take While clause differs from the Where clause in that the Where clause can be used to include all elements from a query that meet a particular condition. The Take While clause includes elements only until the first time that the condition is not satisfied. The Take While clause is most useful when you are working with an ordered query result.

Example

The following code example uses the Take While clause to retrieve results until the first customer without any orders is found.

Public Sub TakeWhileSample()
    Dim customers = GetCustomerList()

    ' Return customers until the first customer with no orders is found.
    Dim customersWithOrders = From cust In customers
                              Order By cust.Orders.Count Descending
                              Take While HasOrders(cust)

    For Each cust In customersWithOrders
        Console.WriteLine(cust.CompanyName & " (" & cust.Orders.Length & ")")
    Next
End Sub

Public Function HasOrders(ByVal cust As Customer) As Boolean
    If cust.Orders.Length > 0 Then Return True

    Return False
End Function
See also

Collaborate with us on GitHub

The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.

Additional resources

In this article

Was this page helpful?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4