Here, we will create an array of strings and then access elements of the array using a one-sided range operator and print the result on the console screen.
The one-sided range operator is used to iterates range in one direction. It is an alternative form of closed range operator or half-open range operator.
Program/Source Code:
The source code to demonstrate a one-sided range operator is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we imported a package Swift to use the print() function using the below statement,
Here, we created an array of strings that contains the name of countries. Then we got the length of the array using the count property. After that, we accessed and printed the name of countries using a one-sided range operator on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer