The Wayback Machine - https://web.archive.org/web/20240629165212/https://www.geeksforgeeks.org/dart-comments/
Open In App

Dart – Comments

Last Updated : 12 Nov, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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 false if n is odd
  else
 
      return false; }
 
int main()
{
  int n = 43;
  print(checkEven(n));
  return 0;
}


 

Output: 

false


Previous Article
Next Article

Similar Reads

How to Combine Lists in Dart?
In Dart programming, the List data type is similar to arrays in other programming languages. A list is used to represent a collection of objects. It is an ordered group of objects. The core libraries in Dart are responsible for the existence of List class, its creation, and manipulation. There are 5 ways to combine two or more list: Using addAll()
3 min read
Dart - Super and This keyword
Super Keyword in Dart: In Dart, super keyword is used to refer immediate parent class object. It is used to call properties and methods of the superclass. It does not call the method, whereas when we create an instance of subclass than that of the parent class is created implicitly so super keyword calls that instance. Advantages of super keyword:
3 min read
Dart - Standard Input Output
Standard Input in Dart: In Dart programming language, you can take standard input from the user through the console via the use of .readLineSync() function. To take input from the console you need to import a library, named dart:io from libraries of Dart. About Stdin Class: This class allows the user to read data from standard input in both synchro
2 min read
Dart - Unit Testing
Unit Testing is a process of testing individual components of a software/application separately, to ensure that each component is functioning as intended. It provides multiple advantages such as - Ability to test out individual components without running the whole software/application.Pinpoint errors easily inside a specific component. Dart provide
3 min read
Generators in Dart
Generators in Dart allows the user to produce a sequence of value easily. One can generate a sequence of values in dart with the help of two generator functions : Synchronous Generator: Returns an Iterable object.Asynchronous Generator: Returns a Stream object.Synchronous Generator in DartThe synchronous generator returns an iterable object i.e. it
2 min read
Dart - Late Keyword
In Flutter, the late keyword is used to indicate that a non-nullable variable will be initialized later in the code. if the non-nullable variable does not initialize before it using, it raised an error. For Example Let's create a non-nullable variable _title of type String and make it late. late String _title; Now if we do not initialize this varia
4 min read
Dart - Loops
A looping statement in Dart or any other programming language is used to repeat a particular set of commands until certain conditions are not completed. There are different ways to do so. They are: for loopfor... in loopfor each loopwhile loopdo-while loop for loop For loop in Dart is similar to that in Java and also the flow of execution is the sa
2 min read
Switch Case in Dart
In Dart, switch-case statements are a simplified version of the nested if-else statements. Its approach is the same as that in Java. Syntax: switch ( expression ) { case value1: { // Body of value1 } break; case value2: { //Body of value2 } break; . . . default: { //Body of default case } break; } The default case is the case whose body is executed
2 min read
Dart - Loop Control Statements (Break and Continue)
Dart supports two types of loop control statements: Break Statement Continue Statement Break Statement: This statement is used to break the flow of control of the loop i.e if it is used within a loop then it will terminate the loop whenever encountered. It will bring the flow of control out of the nearest loop. Syntax: break; Example 1: Using break
4 min read
Instance and class methods in Dart
Dart provides us with the ability to create methods of our own. The methods are created to perform certain actions in class. Methods help us to remove the complexity of the program. It must be noted that methods may and may not return any value and also it may or may not take any parameter as input. Methods in a class can be either an object method
2 min read
Article Tags :
three90RightbarBannerImg