---
title: next()
framework: swift
role: symbol
role_heading: Instance Method
path: swift/asyncthrowingprefixwhilesequence/iterator/next()
---

# next()

Produces the next element in the prefix-while sequence.

## Declaration

```swift
mutating func next() async throws -> Base.Element?
```

## Discussion

Discussion If the predicate hasn’t failed yet, this method gets the next element from the base sequence and calls the predicate with it. If this call succeeds, this method passes along the element. Otherwise, it returns nil, ending the sequence. If calling the predicate closure throws an error, the sequence ends and next() rethrows the error.
