0

Guys i have a doubt

How to print array elements in array just array elements, whenever i print array like : let array = [1,2,3,5] print("Array elements are \(array)") Output: [1,2,3,5] My question why square brackets are also being displayed in output :/

8th Sep 2020, 7:38 AM
Sreenesh
Sreenesh - avatar
4 Respuestas
+ 1
I don't understand the code, can u explain me what is "number" "terminator:" and why we used double quotes?
8th Sep 2020, 10:10 AM
Sreenesh
Sreenesh - avatar
+ 1
Okay if you want to print the individual elements...,it is very easy. Do this let array = [1,2,3,5] for number in array{ print("Array element: \(number) This will print Array element : 1 Array element : 2 ..............
10th Sep 2020, 3:29 PM
🔥 Destiny 🔥
0
You can use for-loop to print the elements one by one let arr = [ 1, 2, 3, 4, 5 ] for number in arr { print(number, terminator : " ") }
8th Sep 2020, 9:25 AM
Ipang
0
<number> is just a variable used in the for-loop. Its content changes with every loop iteration, it will contain each array element, one at a time, from the first element to the last. In simple terms it can be understood as "for each <number> (as element) in array <arr>". About the 'terminator', and the double quotes, you may understand better by reading this 👇 https://www.programiz.com/swift-programming/basic-input-output
8th Sep 2020, 1:31 PM
Ipang