Dart Tutorial

Dart Tutorial Single-Page Application Architecture Dart Features Dart Installation Guide Dart Basic Program Dart Syntax Dart Keywords Dart Variables Dart Comments Dart Standard Input Output Dart Important Concepts

Data Types

Built-in Data Types Numbers Strings Booleans Lists Sets Maps Runes and Graphemes Symbols Enumerations Constants Queues

Other data types

Objects Future and stream Iterable Miscellaneous types

OPERATORS

Precedence and associativity Arithmetic operators Equality and Relational operators Type Test Operators Assignment Operators Logical Operators Bitwise and Shift Operators Miscellaneous operators

Control Flow Statements

Introduction If statement If-else statement If-else-if statement Loops Switch and case Dart Break And Continue Assert In Dart

FUNCTIONS

Dart function Types of Functions Anonymous function main( ) function Lexical scope and closure Recursion Common Collection Methods

Object Oriented Concepts

Dart Object-Oriented Concepts Dart Classes Dart Constructors Dart This Keyword Dart Super Keyword Static Members Method Overriding Dart Interfaces Inheritance Dart Abstract Classes Dart Builder Classes Dart Callable Classes

Dart Type System

Dart Type System Dart Soundness Dart Type Inference

MISCELLANEOUS

Dart Isolates Dart Typedef Dart Metadata Dart Packages Dart Generics Dart Generators Dart Concurrency Dart Unit Testing Dart Html Dom Dart URIs Dart Extends, With and Implements Keywords Dart Optional Parameters Rust Vs Dart C++ vs Dart Golang Vs Dart Dart Basics Exception Handling

Dart If statement

If statement is used to set the control on the lines of code. Using if statement, block of code is executed only if the expression in the statement returns true. If it returns false then the statements following the end of the if statement is executed.

Syntax :

if ( condition )

{

            Statements;

}

This condition is a test expression that evaluated to Boolean True or False and the execution of statements is based on these Boolean values.

Program

Consider the following code in dart that contains if statement,

import 'dart:io';

void main( )

{

    print( " Enter your age : " ) ;

    int? age = int.parse( stdin.readLineSync( ) ! ) ;

    if ( age >= 18 )

    {

            print( " You are eligible to vote ! \n " ) ;

    }

  }

Output:

Enter your age :

25

You are eligible to vote !

Program

Consider the following code in dart that contains multiple if statements,

import 'dart:io';

void main( )

{

    print( " Enter the value of x : " ) ;

    int? x = int.parse( stdin.readLineSync( ) ! ) ;

    print( " Enter the value of y : " ) ;

    int? y = int.parse( stdin.readLineSync( ) ! ) ;

    if ( x > y )

    {

     print( " x is greater than y \n " ) ;

    }

    if ( x < y )

    {

     print( " x is less than y \n " ) ;

    }

    if ( x == y )

    {

     print( " x is equal to y \n " ) ;

    }

}

Output

Enter the value of x :

25

Enter the value of y :

50

x is less than y

Enter the value of x :

50

Enter the value of y :

25

x is greater than y

Enter the value of x :

50

Enter the value of y :

50

x is equal to y