Skip While 子句 (Visual Basic)Skip While Clause (Visual Basic)

只要指定的條件為 true,即略過集合中的項目,然後傳回其餘項目。Bypasses elements in a collection as long as a specified condition is true and then returns the remaining elements.

語法Syntax

Skip While expression  

組件Parts

詞彙Term 定義Definition
expression 必要項。Required. 表示要測試的元素的條件運算式。An expression that represents a condition to test elements for. 此運算式必須傳回Boolean值或功能對等項目,例如Integer評估為BooleanThe expression must return a Boolean value or a functional equivalent, such as an Integer to be evaluated as a Boolean.

備註Remarks

Skip While子句會略過從查詢結果的開始,直到所提供的項目expression傳回falseThe Skip While clause bypasses elements from the beginning of a query result until the supplied expression returns false. 在後expression傳回false,查詢會傳回所有剩餘的項目。After expression returns false, the query returns all the remaining elements. expression會忽略其餘的結果。The expression is ignored for the remaining results.

Skip While子句不同Where中的子句Where子句可以用來排除不符合特定條件的查詢中的所有項目。The Skip While clause differs from the Where clause in that the Where clause can be used to exclude all elements from a query that do not meet a particular condition. Skip While子句會排除項目只會保存未滿足條件的第一次。The Skip While clause excludes elements only until the first time that the condition is not satisfied. Skip While子句在當您正在使用的已排序的查詢結果時十分實用。The Skip While clause is most useful when you are working with an ordered query result.

您可以使用連線,略過特定數目的查詢結果的結果從一開始Skip子句。You can bypass a specific number of results from the beginning of a query result by using the Skip clause.

範例Example

下列程式碼範例使用Skip While子句來略過的結果,直到找到第一個客戶,從美國傳為止。The following code example uses the Skip While clause to bypass results until the first customer from the United States is found.

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

另請參閱See also