Swift program to print Hello World!


This tutorial will discuss how to write swift program to print Hello World.

Hello world programs are the most basic program of any programming language. It is used to learn how we can simply print “Hello world” on the screen using Swift language.

Example

Hello world program

The following program shows how to print hello world.

import Swift

// Printing hello world
print("Hello World")

Output

Hello World

Here we simply print hello world on the output screen using print() function. The syntax of Swift is quit easy and time saver. Like other languages you did not required to semicolon to end the statement. But you can use if you want to write multiple statements in the single line.

Note − To run this program make sure that Swift is properly installed in your system.

Basic elements of Swift Program

Import Libraries − In Swift, import keyword is used to import swift libraries. For example, import Swift is library is used to access all the symbols defined inside the swift language.

Syntax

Following is the syntax −

import libraryName

Comments − Comments are the non-executable text in our program that are used to make codes more understandable. They are always ignored by the Swift compiler. Single line comments are represented by (//) whereas multi line comments are enclosed in between (/*….*/)

Syntax

Following is the syntax −

//Single line comment
And
/* Multi Line comment */

print() − print() is in-built function which is used to print the result on the screen.

Syntax

Following is the syntax −

print(“Hello People”)

Updated on: 13-Dec-2022

246 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements