Flutter Bootcamp SESSION #1 - Setting up flutter development environment - Installing dart-SDK

105 Просмотры
Издатель
Complete introduction to dart programming language

Dart Programming - Syntax

Syntax defines a set of rules for writing programs. Every language specification defines its own syntax. A Dart program is composed of −
• Variables and Operators
• Classes
• Functions
• Expressions and Programming Constructs
• Decision Making and Looping Constructs
• Comments
• Libraries and Packages
• Typedefs
• Data structures represented as Collections / Generics

Your First Dart Code
Let us start with the traditional “Hello World” example −

main() {
print("Hello World!");
}




Dart Programming - Data Types
One of the most fundamental characteristics of a programming language is the set of data types it supports. These are the type of values that can be represented and manipulated in a programming language.
The Dart language supports the following types−
• Numbers
• Strings
• Booleans
• Lists
• Maps


Dart Programming – Variables
A variable is “a named space in the memory” that stores values. In other words, it acts a container for values in a program. 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.

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';
All variables in dart store a reference to the value rather than containing the value. The variable called name contains a reference to a String object with a value of “Smith”.



Dart Programming – Operators

expression is a special kind of statement that evaluates to a value. Every expression is composed of −

Operands − Represents the data

Operator − Defines how the operands will be processed to produce a value.

Consider the following expression – "2 + 3". In this expression, 2 and 3 are operands and the symbol "+" (plus) is the operator.

In this chapter, we will discuss the operators that are available in Dart.

• Arithmetic Operators
• Equality and Relational Operators
• Type test Operators
• Bitwise Operators
• Assignment Operators
• Logical Operators


Sr.No Operators & Meaning
1 +
Add
2 −
Subtract
3 -expr
Unary minus, also known as negation (reverse the sign of the expression)
4 *
Multiply
5 /
Divide
6 ~/
Divide, returning an integer result
7 %
Get the remainder of an integer division (modulo)
8 ++
Increment
9 --
Decrement

Equality and Relational Operators
Relational Operators tests or defines the kind of relationship between two entities. Relational operators return a Boolean value i.e. true/ false.

Assume the value of A is 10 and B is 20.

Dart Programming – Loops

At times, certain instructions require repeated execution. Loops are an ideal way to do the same. A loop represents a set of instructions that must be repeated. In a loop’s context, a repetition is termed as an iteration.
The following figure illustrates the classification of loops −

Dart Programming - Decision Making
A conditional/decision-making construct evaluates a condition before the instructions are executed.

Conditional constructs in Dart are classified in the following table.
Sr.No Statement & Description
1 if statement
An if statement consists of a Boolean expression followed by one or more statements.
2 If...Else Statement
An if can be followed by an optional else block. The else block will execute if the Boolean expression tested by the if block evaluates to false.
3 else…if Ladder
The else…if ladder is useful to test multiple conditions. Following is the syntax of the same.
4 switch…case Statement
The switch statement evaluates an expression, matches the expression’s value to a case clause and executes the statements associated with that case.
Категория
Язык программирования Dart
Комментариев нет.