This repository contains exercises for learning Dart.
The Hello World exercise is a simple program that prints "Hello, World!" to the console.
To run an exercise, navigate to its directory and use the dart run
command. For example:
cd exercises/01-basic
dart run 01-hello-world.dart
The Data Types exercise demonstrates the usage of different data types in Dart. It declares variables of various types and prints their values.
The exercise covers:
- Numeric types (
int
anddouble
) - Nullable types
- String interpolation
- Multiline strings
- Boolean types
- Lists and Sets
- Maps or Dictionaries
In the exercise, you'll also learn how to manipulate lists and sets in Dart. A list of villains is created and then updated by changing the villain at index 0 and adding a new villain at the end. The list is then converted to a set to remove any duplicates, and then converted back to a list.
To run this exercise, use the following commands:
cd exercises/01-basic
dart run 02-datatypes.dart
The Final and Const exercise demonstrates the usage of final
and const
variables in Dart. It declares final
, const
, and late final
variables, and prints their values. It also shows how to declare final
and const
lists and the difference between them.
The exercise covers:
final
variablesconst
variableslate final
variablesfinal
listsconst
lists
To run this exercise, use the following commands:
cd exercises/01-basic
dart run 03-finalConst.dart
The Comments exercise demonstrates the usage of different types of comments in Dart. It includes inline comments, multiline comments, and documentation comments.
The exercise covers:
- Inline comments
- Multiline comments
- Documentation comments
To run this exercise, use the following commands:
cd exercises/01-basic
dart run 04-comments.dart
The Arithmetic Operators exercise demonstrates the usage of different arithmetic operators in Dart. It includes addition, subtraction, multiplication, division, modulus, and increment/decrement operators.
The exercise covers:
- Addition (
+
) - Subtraction (
-
) - Multiplication (
*
) - Division (
/
and~/
) - Modulus (
%
) - Increment (
++
) - Decrement (
--
) - Addition assignment (
+=
) - Subtraction assignment (
-=
)
To run this exercise, use the following commands:
cd exercises/01-basic
dart run 05-operators-arit.dart
The Other Operators exercise demonstrates the usage of different types of operators in Dart, including relational and type test.
The exercise covers:
- Relational operators (
>
,<
,>=
,<=
,!=
,==
) - Type test operators (
is
,is!
)
To run this exercise, use the following commands:
cd exercises/01-basic
dart run 06-operators.dart
The Taking Input exercise demonstrates how to take input from the user in Dart using the stdin.readLineSync()
function. It covers:
- Importing the
dart:io
library - Using the
stdin.readLineSync()
function to take user input - Parsing the input to different data types
To run this exercise, use the following commands:
cd exercises/02-control
dart run 01-take-input.dart
The If-Else Statements exercise demonstrates the usage of if-else control structures in Dart. It covers:
- Using
if
statements to control the flow of the program - Using
else
statements to provide an alternative path for the program - Using
else if
statements to check multiple conditions
To run this exercise, use the following commands:
cd exercises/02-control
dart run 02-ifelse.dart
The If-Else Exercise is a practice exercise for using if-else control structures in Dart. It covers:
- Using
if
statements to control the flow of the program - Using
else
statements to provide an alternative path for the program - Using
else if
statements to check multiple conditions
To run this exercise, use the following commands:
cd exercises/02-control
dart run 02-exercise-ifelse.dart