Skip to content
Related Articles

Related Articles

Improve Article

Dart – Comments

  • Difficulty Level : Expert
  • Last Updated : 21 Jul, 2020

In every programming language comments play an important role for a better understanding of the code in the future or by any other programmer. Comments are a set of statements that are not meant to be executed by the compiler. They provide proper documentation of the code. 

Types of Dart Comments: 

  1. Dart Single line Comment. 
  2. Dart Multiline Comment. 
  3. Dart Documentation Comment. 

1. Dart Single line Comment: Dart single line comment is used to comment a line until line break occurs. It is done using a double forward-slash (//). 

// This is a single line comment. 

Example: 

Dart






int main() 
  double area = 3.14 * 4 * 4; 
  // It prints the area
  // of a circle of radius = 4 
  print(area); 
  
return 0; 
}

 

Output:

50.24

2. Dart Multi-Line Comment: Dart Multiline comment is used to comment out a whole section of code. It uses ‘/*’ and ‘*/’ to start and end a multi-line comment respectively. 

/* 

These are 

multiple line 

of comments 

*/ 

Example: 

Dart




int main() 
  var lst = [1, 2, 3]; 
    
  /* 
  It prints 
  the whole list 
  at once 
  */ 
  print(lst); 
    
return 0; }

 

Output: 

[1, 2, 3]

3. Dart Documentation Comment: Dart Documentation Comments are a special type of comment used to provide references to packages, software, or projects.Dart supports two types of documentation comments “///”(C# Style) and “/**…..*/”(JavaDoc Style). It is preferred to use “///” for doc comments as many times * is used to mark list items in a bulleted list which makes it difficult to read the comments. Doc comments are recommended for writing public APIs. 

/// This is 

/// a documentation 

/// comment 

Example: 

Dart




bool checkEven(n){ 
  /// Returns true
  /// if n is even 
  if(n%2==0) 
  
      return true
  /// Returns fakse if n is odd 
  else 
  
      return false; } 
  
int main() 
  int n = 43; 
  print(checkEven(n)); 
  return 0; 

 

Output: 

false



My Personal Notes arrow_drop_up
Recommended Articles
Page :