← Back to Swift Course | Chapter 1: Setup & Basics | Lesson 6 of 7

Swift में Comments

Comments छोटे notes हैं जो आप humans के पढ़ने के लिए अपने code में छोड़ते हैं; computer इन्हें पूरी तरह नज़रअंदाज़ करता है।
Syntax
swift
// single-line comment

/* multi-line
   block comment */

/* outer /* nested */ outer */

Single-Line Comments

एक single-line comment // से शुरू होता है और उस line के आखिर तक जारी रहता है। Compiler उस line पर // के बाद की हर चीज़ पूरी तरह नज़रअंदाज़ करता है।

उदाहरण: Single-Line Comments

markup
// This prints a greeting
print("Hello, Swift!") // this part is also a comment

Multi-Line Block Comments

एक block comment /* से शुरू होता है और */ पर खत्म होता है, और कई lines तक span कर सकता है, इसे लंबे explanations के लिए उपयोगी बनाते हुए।

उदाहरण: Multi-Line Block Comments

markup
/*
 This program demonstrates
 multi-line block comments
*/
print("Block comments explained")

Nested Block Comments

C या Java के विपरीत, Swift block comments को एक-दूसरे के अंदर nested होने देता है, जो code के एक section को comment out करना आसान बनाता है जिसमें पहले से एक block comment है।

Note: यह code के एक हिस्से को temporarily disable करने के लिए handy है जिसके अंदर पहले से comments हैं।

उदाहरण: Nested Block Comments

markup
/* outer comment /* nested inner comment */ still outer */
print("Swift supports nested block comments")
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह मानना कि comments program के चलने के तरीके को प्रभावित करते हैं; compiler इन्हें पूरी तरह skip कर देता है।
  2. comments का उपयोग obvious code explain करने के लिए करना बजाय यह explain करने के कि कोई non-obvious decision *क्यों* लिया गया।
  3. यह भूल जाना कि 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.