Swift Hello World Program


Writing Your First Swift Program

Create a file named hello.swift. In Swift, file naming is flexible, but we’ll use hello.swift for clarity.

import Foundation

print("Hello, World!")
Hello, World!

Running the Program

If you're using a local environment like Terminal with Swift installed, run:

swift hello.swift

What happens during execution?

  • The Swift interpreter reads and executes the source code.
  • print("Hello, World!") sends output to the console.

You’ve successfully executed your first Swift program!

Common Issues to Watch For

  • Missing quotes: Make sure strings are enclosed in double quotes.
  • No semicolons needed: Swift doesn’t require semicolons at the end of lines (unless multiple statements are on one line).
  • Correct casing: Swift is case-sensitive. Print is not the same as print.

Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...