Swift में Comments
// single-line comment
/* multi-line
block comment */
/* outer /* nested */ outer */
Single-Line Comments
एक single-line comment // से शुरू होता है और उस line के आखिर तक जारी रहता है। Compiler उस line पर // के बाद की हर चीज़ पूरी तरह नज़रअंदाज़ करता है।
उदाहरण: Single-Line Comments
// This prints a greeting
print("Hello, Swift!") // this part is also a comment
Login to try C/C++/Java/PHP code in the editor
Multi-Line Block Comments
एक block comment /* से शुरू होता है और */ पर खत्म होता है, और कई lines तक span कर सकता है, इसे लंबे explanations के लिए उपयोगी बनाते हुए।
उदाहरण: Multi-Line Block Comments
/*
This program demonstrates
multi-line block comments
*/
print("Block comments explained")
Login to try C/C++/Java/PHP code in the editor
Nested Block Comments
C या Java के विपरीत, Swift block comments को एक-दूसरे के अंदर nested होने देता है, जो code के एक section को comment out करना आसान बनाता है जिसमें पहले से एक block comment है।
उदाहरण: Nested Block Comments
/* outer comment /* nested inner comment */ still outer */
print("Swift supports nested block comments")
Login to try C/C++/Java/PHP code in the editor
- यह मानना कि comments program के चलने के तरीके को प्रभावित करते हैं; compiler इन्हें पूरी तरह skip कर देता है।
- comments का उपयोग obvious code explain करने के लिए करना बजाय यह explain करने के कि कोई non-obvious decision *क्यों* लिया गया।
- यह भूल जाना कि Swift में block comments
/* */nested हो सकते हैं, कई दूसरी C-family languages के विपरीत, जो styles mix करते समय confusion का कारण बन सकता है।
//एक single-line comment शुरू करता है जो line के आखिर तक चलता है।/* ... */एक multi-line block comment मार्क करता है।- Swift विशिष्ट रूप से nested block comments (
/* /* ... */ */) allow करता है। - अच्छे comments explain करते हैं कि code कुछ *क्यों* करता है, सिर्फ *क्या* नहीं।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: