0% found this document useful (0 votes)
22 views

Dart Programming Language 1

datrt syntax

Uploaded by

studentdatapewt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Dart Programming Language 1

datrt syntax

Uploaded by

studentdatapewt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 26

Dart Programming Language

Dart

 Dart is an open-source general-purpose programming language.


 originally developed by Google and later approved as a standard by ECMA.
 Dart is a new programming language meant for the server as well as the browser.
 Dart is an object-oriented language with C-style syntax which can optionally
trans compile
into JavaScript
Run time environment – Online text editor

 https://dartpad.dartlang.org/
Sample syntax

void main() {
print('hello world');
}
Dart syntax

 Whitespace and Line Breaks- Dart ignores spaces, tabs, and newlines that appear
in
programs
 Dart is case-sensitive- means that Dart differentiates between uppercase and
lowercase
characters.
 Statements end with a Semicolon -Each dart statement must end with a semicolon
(;).
 Comments in Dart
 Single-line comments ( // ) − Any text between a "//" and the end of a
line is treated as a
comment
 Multi-line comments (/* */) − These comments may span multiple lines.
Data type in dart

 The Dart language supports the following types−


• Numbers
• Strings
• Booleans
• Lists
• Maps
Naming Rule for variable

 Variable names are called identifiers. Following are the naming rules for an
identifier −
• Identifiers cannot be keywords.
• Identifiers can contain alphabets and numbers.
• Identifiers cannot contain spaces and special characters, except the underscore
(_) and the
dollar ($) sign.
• Variable names cannot begin with a number.
• Variable name are case sensitive.

• Int num;
• NUM=10;
Numbers

Dart Integer

used to store whole numbers.(64 bits)


int age =25;

Dart Double
used to store a 64 bit floating-point number
double pi=3.14;

Dart String
used to store series or sequence of character,letters,numbers and specical
character.
String name='smith';
variable

Dart Boolean
used to stored true or false
bool isValid=true;

Dart lists
is used to represent a collection of objects.
var list=[1,2,3];

Dart Maps
is used to represent a set of values as key-value pairs.
var weekDays={'Day1':'Mon','Day1':'Tue','Day1':'Wed'};
Type Syntax

 A variable must be declared before it is used. Dart uses the var keyword to
achieve the
same. The syntax for declaring a variable is as given below .

var name = 'Smith’;


Print (name);
Default value

 in Dart, uninitialized variables are provided with an initital value is null

syntax
void main() {
var a;
print(a);
}
Operator in dart

Add +
Subtract -
Multiply *
Divide /
Get the remainder of an integer division %
Increment ++
decrement --
Equality and Relational Operators

Operator Description Example


> Greater than (A > B) is False
< Lesser than (A < B) is True
>= Greater than or equal to (A >= B) is False
<= Lesser than or equal to (A <= B) is True
== Equality (A==B) is False
!= Not equal (A!=B) is True
Dart Programming - If Else Statement

if(boolean_expression){
// statement(s) will execute if the Boolean expression is true.
} else {
// statement(s) will execute if the Boolean expression is false.
}
If the Boolean expression evaluates to be true, then the if block
of code will be executed, otherwise else block of code will be
executed.
Example - syntax

Live Demo

void main() {
var num = 12;
if (num % 2==0) {
print("Even");
} else {
print("Odd");
}
}
Parse()-

 The parse() static function allows parsing a string containing numeric literal
into a
number.

void main() {
print(num.parse('12'));
print(num.parse('10.91'));
}
${}

 use "${}" can be used to interpolate the value of a Dart expression within
strings.

void main() {
int num1=10;
int num2=20;

int sum=num1+num2;
print ("total sum result is ${sum}");
}
Operator +

 The operator plus (+) is a commonly used mechanism to concatenate /


interpolate strings.

void main() {
String str1 = "hello";
String str2 = "world";
String res = str1+str2;

print("The concatenated string : ${res}");


}
Methods to Manipulate Strings

1 toLowerCase() Converts all characters in this string to lower case.

2 toUpperCase() Converts all characters in this string to upper case.

3 trim() Returns the string without any leading and trailing whitespace.

4 compareTo() Compares this object to another.

replaceAll() Replaces all substrings that match the specified pattern with a
5
given value.
Methods to Manipulate Strings

split() Splits the string at matches of the specified delimiter and


6
returns a list of substrings.

substring() Returns the substring of this string that extends from startIndex,
7
inclusive, to endIndex, exclusive.

8 toString() Returns a string representation of this object.


looping
For loop

void main() {
for(int i=1;i<=5;i++){
print ("Number is${i}");
}

}
While loop

void main() {
int i=1;
while(i<5){
print("Number is ${i}");
i++;
}

}
Do while loop

void main() {
int i=1;
do {
print("Number is ${i}");
i++;
}while(i<=5);

You might also like