Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

String Length

var varA = "Hello, Swift 4!"

print( "\(varA), length is \((varA.count))" )

String Concatenation

let constA = "Hello,"
let constB = "World!"

var stringA = constA + constB
print( stringA )

String Interpolation

var varA = 20
let constA = 100
var varC:Float = 20.0

var stringA = "\(varA) times \(constA) is equal to \(varC * 100)"
print( stringA )

Empty String

// Empty string creation using String literal
var stringA = ""

if stringA.isEmpty {
   print( "stringA is empty" )
} else {
   print( "stringA is not empty" )
}

// Empty string creation using String instance
let stringB = String()

if stringB.isEmpty {
   print( "stringB is empty" )
} else {
   print( "stringB is not empty" )
}

Create a String

// String creation using String literal
var stringA = "Hello, Swift 4!"
print( stringA )

// String creation using String instance
var stringB = String("Hello, Swift 4!")
print( stringB )

//Multiple line string

let stringC = """
Hey this is a
example of multiple Line
string by tutorialsPoint 

"""
print(stringC)

Fallthrough Statement

var index = 10

switch index {
   case 100 :
      print( "Value of index is 100")
      fallthrough
   case 10,15 :
      print( "Value of index is either 10 or 15")
      fallthrough
   case 5 :
      print( "Value of index is 5")
   default :
      print( "default case")
}

Fallthrough Statement Program

var index = 10

switch index {
   case 100 :
      print( "Value of index is 100")
   case 10,15 :
      print( "Value of index is either 10 or 15")
   case 5 :
      print( "Value of index is 5")
   default :
      print( "default case")
}

Break Statement

var index = 10

repeat {
   index = index + 1
   if( index == 15 ){
      break
   }
   print( "Value of index is \(index)")
} while index < 20

Continue Statement

var index = 10

repeat {
   index = index + 1
   if( index == 15 ){
      continue
   }
   print( "Value of index is \(index)")
} while index < 20

Do While Loop

var index = 10

repeat {
   print( "Value of index is \(index)")
   index = index + 1
}
while index < 20

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.