Variable Operator String loops in Swift How work?

404

Introduction

The Swift is a powerful programming language for ios. The swift code lightweight that produces software that runs fast. Swift 4 utilizes existing runtime from the current Obj-C framework on Mac OS and iOS.

Swift 4 embraces the best of C and Objective-C. Swift 4 is another programming language created by Apple Inc for iOS and OS X development. which empowers Swift 4 projects to keep running on many existing iOS 6.

You will learn in this section

  1. Variable
  2. Constant
  3. Data types
  4. Operator
  5. Arithmetic operator
  6. Comparison operator
  7. logical operator
  8. String
  9. Loop
  10. Array

What is variable

In the swift variable hold, some data in swift. The data could be a value and could be the reference.  The ‘var’ keyword could be used to declare it. The variable should be created before it uses it.

A variable is a quantity whose value is changed during execution of the programs. The variable is the container that has some kinds of value that are the point to the memory location.

The variable in computer language is the values that change independently. When you declare a variable it holds some memory. While some space is reserved for it. When you will create a variable its store some data in the memory location.Example: like you declare int =40; its stored in memory like 01010110.

 

The variable should be descriptive. ‘=’ is assignment operator that assigns the value of left-hand side to the right-hand side like zubtitle= “welcome to the swift” contain the message.

What is constant

The constant is the value that can not change during the execution of the program. They are different types of constant. The Integer constant Floating constant string constant or character constant.

The constant variable used when you will not change a value.

Data types in swifts

Variable Operator String loops in Swift How work?

The int Data Type

The int represents the integer data always used to declare integer types of data. its represent the whole number. The number without the fraction.

The float Data Type

The floats data types represent floating data types that lies in the form of decimal or exponential notation. The floating data type may be single or double.

The Double Data Type

This similar to integer types of data but store a large value of an integer.

The Boolean Data Type

The boolean condition most of the time is used for checking the values. The boolean is the logical type. The boolean value lies in the form of true and false. The boolean is used for making decisions.

 Operator in Swift

They are three types of operators in swift. They are

  • The unary operator
  • Binary operator
  • Ternary operators

The unary operator works with one object. Where the binary operator works with two objects. While the ternary operators with three objects. The following is an example of a ternary operator.

The following is the ternary operator. The value of ‘something’ if true then “today I am ok” is executed its value is true otherwise its value is false.

Arithmetic Operator

As the name implies the arithmetic operator is to operator arithmetic operator. They are different types of the arithmetic operator are used in swift. Some of them are commonly used + – / *

The comparison operator

The comparison operator always returns values in the form of boolean true or false. The statement executes one after other depending on the condition if the condition is true then the block of a statement executes that are under the if statement otherwise if then given statement is false then the statement or set of statement ignored and control moves to next statement.

Logical operator

The logical operator is the combination of relation expression or relational condition. it is also called the compound condition. It also gives the output in boolean forms like true or false. The are three basic types.

  • AND operator—>&&
  • OR operator—>||
  • Not operator—>!

The AND operator have to use the combination of two or more relation expression. If both conditions give true value then it returns true value otherwise its give false value.

The OR operator has used a combination of two or more relation expression. if one of a condition is true then its return true if both are false then it returns false.

The Not operator is a unary operator it inverts the value in the compound expression.

String

A string is a progression of characters for example “Greeting Appears Here”. The swift string is spoken to by the string compose. The substance of a String can be gotten to in different routes, including as a gathering of Character esteems.

Interpolation String

Interpolation string is an approach to building another string an incentive from a blend of constants and variable articulations by including their qualities inside a string exacting. The strings interpolation same like concatenation put the method is different

String Concatenation

Using + operator to concatenation two string.

In swift, they are built method to show string upper latter or lower latter.

Loops

They are many situations where the set of a statement executed repeatedly is called a loop. The statement under the loop is executed repeatedly as the given condition remain true. Its stop the execution when the condition is false.

Most probably three types of loop are used in swift. Swift4 programming language gives the accompanying sorts of the loop to deal with lopping prerequisites

  • While loop
  • For each loop
  • For range loop
While loop

It is condition loop. Its executable until given condition true.Its first test the condition before execution.

Here statement might be a solitary statement or a combination of the statement. The condition might be any expression. The loop emphasizes while the condition is valid. At the point when the condition turns out to be false. The program control goes to the line promptly following the loop.

For range loop

The for range loop define the range. You can use it where you know the size of the array.

For each loop

For each loop is defined, the range all the items inside the array are executed. It’s minimized the programming error and makes the code more reliable. The following is the basic syntax.

Array

The array is the collection of data ordered by indexes. Every array has an index which has a particular item. You will access the element using index number. The following is a simple way to declare an array.

How to access the elements of an array using the index number. You will also change the order of the array you can access the element is either ascending order or descending order.

You will also access all the elements of the array. How to access all the elements without an index number? So simple way Using for each loop you will access all the element. here is the example.

You can add more elements of the array that already created and remove the element in existing array.

Remove the element in the array. The cat at the index number 1 position has deleted.

you will also count the element in an array without the for the loop.

So how you will create an empty array. The following is the example.

Conclusion

Here in this post-Variable Operator String loops in Swift How work? I had explained the basic programming concepts. I had to explain what is the variable difference between variable and constant. The data types that most commonly used in swift. I also define the comparison operator arithmetic operator relation operator with the example. The last section I explain the two the two important concepts string and loops with examples. To learn more about Swift for beginners.