Monday, August 10, 2020

swift basic syntax

 import Foundation


let age = 30 //constant

var name = "Nick" //variable


var age1 : Int = 30

var weight = 45.678

let naame1 : String = "Nick"


print(age1)

age * Int(weight)

Double(age) * weight


//Supports Float also but less precision.


var carRideWaterslide : Bool = false

var carRideWaterslide1 = true


var height = 76


if height >= 50 || weight >= 100 {

 print("you can go down the waterslide")

}

else

{

print("come back later")

}



if name == "Nick" && age == 30{

print("that's nick!")

}



//var movies = ["Sandlot","Emperor's New Groove","LEGO Movie"]

var movies : [String] = ["Sandlot","Emperor's New Groove","LEGO Movie"]

movies

movies[0]

movies.append(newElement: String)

movies.append("Karthikeya")


var movies1 : [Any] = ["Sandlot","Emperor's New Groove","LEGO Movie",6]

movies.append(7)

movies.insert("Dark Knight Rises", at: 0)//before Sandlot it will be added

movies.remove(at: 0)

movies.count


//constant array,can't add elements later

let movies2 : [Any] = ["Sandlot","Emperor's New Groove","LEGO Movie",6]


for _ in 1...1000{

  print("hello")

 }



for number in 1...10{

 print(number)

 print("\(number).5")

}


for x in 0..<movies.count{

  print("\(x+1). \(movies[x])")

}


_ to signify the numbers readability

if n > 5000000 is same as n > 5000_000



-------


var str = "["


for _ in 1...1000{

  str += "\(Int.random(in: 0...10_000)),"

 }


str + = "]"


print(str)


No comments:

Post a Comment