Popular Posts

Monday, June 16, 2014

Swift - Basics

Let us discover  

Constants and Variables:

In programming languages constant refers to a term whose value never changes during the life of program.  While variable ar ethe container that hold values which can change during life of our porgram.


In SWIFT we  need to declare our constants or variables before hand. To declare a constant we use the word "let" with constant  name.


  • let totalMarks = 50; 

  • the above declared value is an integer constant value. we can declare it with float or string or any other datatype.



  • let totalWeight = 50.70;  

  • Variables can be declared using "var " keyword. It can be of any datatype.


  • var marksObtained = 37;

  • We can declare multiple constants or variables in a single line separated by commas like,

    let max =0, min = 0;


  • var marksObtained = 37, totalMarks = 50


  • We can declare a variable with datatype  as follows.

    • var welcome: String

    This variable is declared of string data type.

    welcome = "Welcome and Hello World to Swift Language";


    To print a line on console we can use

    println("Hello World!!!");


    To print a constant or variable value inside println we have to place constant or variable inside parenthesis and placing a backslash \ before opening paranthesis.


    • println("Hi, and \(welcome)");


    We will explore more in next posts


    No comments:

    Post a Comment