Swift ‘For’ loop

This post was originally posted at https://agrawalsuneet.github.io/blogs/swift-for-loop/ and reposted on Medium on 03rd Dec 2021.

1. Simple for loop in java that iterates from some number to some number incrementing one on each loop pass.

Java code
for (int i = 0; i <= 10; i++){
Swift code
for i in 1...10 {

Things to notice

  • No need to declare the data type of variable.
  • If iterating over a range, we can use (closed range) operator.
  • The lower and upper (including) limit can be defined on both the sides of operator.

Please continue reading at https://agrawalsuneet.github.io/blogs/swift-for-loop/



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store