DEV Community

Cover image for Dart basics - part 1
kururu
kururu

Posted on

Dart basics - part 1

Dart is an open-source general-purpose programming language. It is 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. Introduced by Google, the Dart SDK ships with its compiler.

dart has many similarities to other languages

in this topics we are going to focus in some basics of this new languages so can help you in your journey especially for those who want to try flutter

Variables :

in dart you van create variable use var keywords , or instead you specify the variable type

` var x= 'abdo';

// or

String y ='ahmed';`

using var is what they called it inferred type
so the type of the variable is detected by it's value

Note:
when using var keyword to initialize variable with a value which from specific type you cannot update the variable with value of different type


var x= 'abdo';
x=90; // show an error

Control Structure:

we mean the conditional  and iteration statements including:


-  if elese   
-  switch case
- for loop
- etc
Enter fullscreen mode Exit fullscreen mode

**
IF ELSE**

`int x =9;
if(x>8){
print("x is bigger than 8");
} else {

print("x is less or equal  to 8");
Enter fullscreen mode Exit fullscreen mode

}`

Loop

for(int c=0;c<9;c++){
print(c);
}

same to for loop in other languages like java

there is special loop come with list type like an array
called foreEach

it is a callback for the array , it iterates through all elements of the given array

List numbers =[2,232,23,89];
numbers.forEach((n){
print(n);
});

*SWITCH CASE *

 same as switch case in java and many languages
Enter fullscreen mode Exit fullscreen mode

` var name ='ali';

switch(name){
case 'ahmed':
print('it is ahmed');

  break;
case 'ali':
  print('it is ali');

  break;

default:
   print('none of above');
Enter fullscreen mode Exit fullscreen mode

}
`

continued...

Top comments (0)