Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Increment and Decrement | Loops
Introduction to Dart
course content

Contenido del Curso

Introduction to Dart

Introduction to Dart

1. First Acquaintance with Dart
2. Variables and Data Types
3. Conditional Statements
4. List and String
5. Loops

bookIncrement and Decrement

Increment

Increment operators are used to increase the value of a variable by 1.

Pre-increment operator: ++variable.

The pre-increment operator increments the value of the variable before it is used:

dart

main

copy
12345
void main() { int counter = 0; // Increases the value of `counter` by 1 print(++counter); // 1 }

Post-increment operator: variable++.

The post-increment operator increments the value of the variable after it is used:

dart

main

copy
123456
void main() { int counter = 0; // Increases the value of `counter` by 1 print(counter++); // 0 print(counter); // 1 }

Decrement

Decrement operators are used to decrease the value of a variable by 1.

Pre-decrement operator: --variable:

dart

main

copy
12345
void main() { int counter = 10; // Decrease the value of `counter` by 1 print(--counter); // 9 }

Post-decrement operator: variable--.

The post-decrement operator decrements the value of the variable after it is used:

dart

main

copy
123456
void main() { int counter = 10; // Decrease the value of `counter` by 1 print(counter--); // 10 print(counter); // 9 }

Increment and decrement operators are often used in loops.

This approach maintains the same functionality while reducing the amount of code we need to write.

i ++ is it ?

i ++ is it ?

Selecciona la respuesta correcta

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 5
some-alt