LoginSignup
0
1

More than 5 years have passed since last update.

Swift3 配列の要素を後ろから表示

Last updated at Posted at 2017-09-27

配列を引数として受け取り、最後から順に表示。

配列の要素を逆順に表示

func printArray(it1:[String]){

    //配列の要素数表示
    print(it1.count)

    let max :Int = it1.count - 1

    //max...0と書くのは通用しない。昇順でなければならない
    //for文の中で降順を実現
    for index in 0...max {
        var backIndex = index
        backIndex = max - index
        print(it1[backIndex])
    }
}

printArray(it1: ["000","111","222","333","444","555","666","777","888","999",])
printArray(it1: ["aaa","bbb","ccc","ddd","eee","fff",])
0
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1