// exsw3.swift declare constants, variables, arrays // see exsw3a for sets, dictionaries and classes #if os(OSX) || os(iOS) // for libraries, portable for OSX and Linux import Foundation #elseif os(Linux) import Glibc #endif// print("exsw3.swift running") let c1 = 1 // integer constant // let c2= 1 // error must have space each side of operator var c3 = 2 // integer variable initial value 2 let f1 = 7.5 // floating point constant var f2 = 37.5e-6 // floating point variable let s1 = "unchangeable string" var s2 = "changeable string" print("c1= \(c1)") print("c3= \(c3)") print("f1= \(f1)") print("f2= \(f2)") print("s1= \(s1)") print("s2= \(s2)") // var c4 : Int = 8.2 // error let f3 : Double = 8 // this will be constant 8.0 var f4 : Double = 9 // this will be variable initial value 9.0 print("f3 as integer= \(f3)") print("f4 as integer= \(f4)") // define an empty array var someInts = [Int]() someInts.append(1) someInts.append(2) print("someInts= \(someInts)") someInts = [] // back to empty array // define an initialized array with values of same type var V1 = [1.2, 1.3, 1.4] print("V1= \(V1)") var M2 = [[1.1, 1.2, 1.3],[2.1,2.2,2.3],[3.1,3.2,3.3]] print("M2= \(M2)") var M3 = [[[1.1, 1.2],[2.1,2.2]],[[3.1,3.2],[4.1,4.2]]] print("M3= \(M3)") // define and initialized array with some value var big = [Double](repeating: 0.0, count:1000) print("big[999]= \(big[999])") var M2D = [[Double]](repeating:[Double](repeating:2.0,count:2),count:3) print("M2D=\(M2D)") var M3D = [[[Double]]](repeating:[[Double]](repeating:[Double](repeating:3.0,count:2),count:2),count:2) print("M3D=\(M3D)") print("exsw3.swift finished")