共用方式為


Skip While 子句 (Visual Basic)

一直略過集合中的項目,直到指定的條件不為 true,然後傳回剩餘項目。

Skip While expression

組件

詞彙

定義

expression

必要項。 運算式,表示要對項目測試的條件。 這個運算式必須傳回 Boolean 值或功能上的對等用法,例如待評估為 Boolean 的 Integer。

備註

Skip While 子句會自查詢結果開頭起一直略過項目,直到提供的 expression 傳回 false 為止。 在 expression 傳回 false 之後,查詢會傳回所有剩餘項目。 傳回剩餘結果時會忽略 expression。

Skip While 子句跟Where 子句有個不同點,即 Where 子句可用來排除查詢中所有不符合特定條件的項目。 Skip While 子句則只會排除在第一次不符合條件之前遇到的項目。 當您使用已排序的查詢結果時,Skip While 子句會很有幫助。

您可以使用 Skip 子句,略過查詢結果的前幾筆結果。

範例

下列程式碼範例會使用 Skip While 子句一直略過結果,直到找到第一個美國客戶為止。

Public Sub SkipWhileSample()
  Dim customers = GetCustomerList()

  ' Return customers starting from the first U.S. customer encountered.
  Dim customerList = From cust In customers
                     Order By cust.Country
                     Skip While IsInternationalCustomer(cust)

  For Each cust In customerList
    Console.WriteLine(cust.CompanyName & vbTab & cust.Country)
  Next
End Sub

Public Function IsInternationalCustomer(ByVal cust As Customer) As Boolean
  If cust.Country = "USA" Then Return False

  Return True
End Function

請參閱

參考

Select 子句 (Visual Basic)

From 子句 (Visual Basic)

Skip 子句 (Visual Basic)

Take While 子句 (Visual Basic)

Where 子句 (Visual Basic)

概念

Visual Basic 中的 LINQ 簡介

其他資源

查詢 (Visual Basic)