Skip to content

Commit 01b33e0

Browse files
Update varconst.md
1 parent 1ce512d commit 01b33e0

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

varconst.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
**Published by Arunprasadh C on 21 Apr 2022***Last Updated on 27 Apr 2022*
1+
**Published by Arunprasadh C on 21 Apr 2022***Last Updated on 06 May 2022*
22

33
## Variables, Literals and Constants in Swift
44
### Literals
@@ -32,19 +32,26 @@ var word:String
3232
// Some statements
3333
word = "Hello"
3434
```
35-
#### Declaring Multiple Variables on a single line
36-
Multiple variables can be declared without initialization in a single line provided that the variables are annotated with their types.
35+
#### Defining Multiple Variables on a single line
36+
Multiple variables can be declared/defined with/without initialization in a single line provided that the variables are annotated with their types.
3737

3838
**Syntax :**
3939
```swift
40-
var v1:DataType1, v2:DataType2, v3:DataType3, ...
40+
var v1:DataType1 = optInitialValue1, v2:DataType2 = optInitialValue1, v3:DataType3 = optInitialValue1, ...
4141
```
4242
**Example :**
4343
```swift
44-
var name: String, age: Int, native: String
44+
var name: String = "Kris", age: Int = 22, native: String = "Chennai"
45+
print("\(name), who is \(age) years old, is from \(native).")
4546
```
47+
48+
**Output :**
49+
```
50+
Kris, who is 22 years old, is from Chennai.
51+
```
52+
4653
#### Initializing/Assigning values to Multiple Variables using Tuple Syntax
47-
Multiple variables can be initialized/assigned to values at once using the Tuple Syntax:
54+
Multiple variables can be reassigned to values at once using the Tuple Syntax:
4855

4956
**Syntax :**
5057
```swift

0 commit comments

Comments
 (0)