आपका पहला Swift Program
In this page:
print("text")
print("another line")
The Classic Hello World
किसी भी language में traditional पहला program screen पर एक greeting print करता है। Swift में, built-in print function के कारण यह सिर्फ एक line लेता है, एक साधारण script के लिए कोई imports या boilerplate ज़रूरी नहीं।
उदाहरण: The Classic Hello World
print("Hello, World!")
Login to try C/C++/Java/PHP code in the editor
Running the Program
एक Swift file को swift command को पास करके execute किया जाता है, जो एक step में इसे compile और तुरंत चलाता है, किसी भी output को terminal में print करते हुए।
उदाहरण: Running the Program
swift hello.swift
⚠️ Run this in your own terminal or Node.js environment.
Adding More Statements
एक Swift program बस top से bottom तक executed statements का एक sequence है। आप ज़्यादा print calls जोड़ सकते हैं, और हर एक program चलने पर अपनी खुद की output line produce करता है।
उदाहरण: Adding More Statements
// Print "Hello, World!" to the console
print("Hello, World!")
// Print "Welcome to Swift" to the console
print("Welcome to Swift")
// Print "This is my first program" to the console
print("This is my first program")
Login to try C/C++/Java/PHP code in the editor
- यह भूल जाना कि Swift statements को एक
mainfunction या class wrapper की ज़रूरत नहीं -- एक single file में top-level code बस सीधे चलता है। - File extension गलत नाम देना (जैसे
.swiftके बजाय.txt), जोswiftcommand को इसे पहचानने से रोकता है। - एक command-line Swift script चलाते समय terminal के बजाय एक popup window में output की उम्मीद करना।
- एक minimal Swift program एक single line हो सकता है:
print("Hello, World!")। - Swift files
.swiftextension उपयोग करती हैं औरswift filename.swiftसे चलाई जाती हैं याswiftcसे compile की जाती हैं। main.swift(या एक single-file script) में top-level code सीधे execute होता है, किसी wrapper class की ज़रूरत नहीं।- यह simplicity एक कारण है कि Swift beginners के लिए approachable है।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: