The source code to demonstrate the closed range operator is given below. The given program is compiled and executed successfully.
// Swift program to demonstrate the
// closed range operator
var num:Int=5;
var res:Int=0;
print("Table:")
for val in 1...10 {
res = num*val;
print("\(num)X\(val) = \(res)")
}
In the above program, we imported a package Swift to use the print() function using the below statement,
import Swift;
Here, we created two integer variables num, res, that are initialized 5,0 respectively. Then we iterated the numbers from 1 to 10 using the closed range operator in the for loop and printed the table of number 5 on the console screen.
Program/Source Code:
The source code to demonstrate the closed 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 two integer variables num, res, that are initialized 5,0 respectively. Then we iterated the numbers from 1 to 10 using the closed range operator in the for loop and printed the table of number 5 on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer