For Loop Conversion in Swift

Hi, i have only seen for loop samples that involve indexes or using for item in items.

I come from a java background and i cannot seem to confirm if this can actually be converted to a swift for loop. thoughts?

for (EdgeNode edge = aet.topNode ; (edge != null); edge = edge.next)

Accepted Reply

This for loop exist in C or other, not in Swift since Swift3. https://github.com/apple/swift-evolution/blob/main/proposals/0007-remove-c-style-for-loops.md

You need to use a different pattern.

See examples here: https://forums.kodeco.com/t/how-to-change-c-style-for-loop-to-swift/100180/2

  • Not much in there. but guess the while loop is the only way to go. Thank you.

Add a Comment

Replies

This for loop exist in C or other, not in Swift since Swift3. https://github.com/apple/swift-evolution/blob/main/proposals/0007-remove-c-style-for-loops.md

You need to use a different pattern.

See examples here: https://forums.kodeco.com/t/how-to-change-c-style-for-loop-to-swift/100180/2

  • Not much in there. but guess the while loop is the only way to go. Thank you.

Add a Comment