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

bookIncrement and Decrement

Increment (++) and decrement (--) operators are commonly used to increase or decrease a variable's value by 1. They are especially useful in loops for managing counters.

Increment Operators

  • Pre-increment (++variable): increases the value before usage;
  • Post-increment (variable++): increases the value after usage.

Usage in a loop:

main.dart

main.dart

copy
12345
void main() { for (int i = 0; i < 5; ++i) { print(i); // Outputs: 0, 1, 2, 3, 4 } }

Decrement Operators

  • Pre-decrement (--variable): decreases the value before usage.
  • Post-decrement (variable--): decreases the value after usage.

Usage in a loop:

main.dart

main.dart

copy
12345
void main() { for (int i = 5; i > 0; --i) { print(i); // Outputs: 5, 4, 3, 2, 1 } }

Task

Complete the code so that it prints all numbers from 2 to 10 inclusive.

main.dart

main.dart

copy
12345
void main() { for (int i = 2; i <= 10; ___) { print(i); } }

Use an increment operator.

main.dart

main.dart

copy
12345
void main() { for (int i = 2; i <= 10; i++) { print(i); } }
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 4. Hoofdstuk 5

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Suggested prompts:

Stel mij vragen over dit onderwerp

Vat dit hoofdstuk samen

Toon voorbeelden uit de praktijk

Awesome!

Completion rate improved to 4.55

bookIncrement and Decrement

Veeg om het menu te tonen

Increment (++) and decrement (--) operators are commonly used to increase or decrease a variable's value by 1. They are especially useful in loops for managing counters.

Increment Operators

  • Pre-increment (++variable): increases the value before usage;
  • Post-increment (variable++): increases the value after usage.

Usage in a loop:

main.dart

main.dart

copy
12345
void main() { for (int i = 0; i < 5; ++i) { print(i); // Outputs: 0, 1, 2, 3, 4 } }

Decrement Operators

  • Pre-decrement (--variable): decreases the value before usage.
  • Post-decrement (variable--): decreases the value after usage.

Usage in a loop:

main.dart

main.dart

copy
12345
void main() { for (int i = 5; i > 0; --i) { print(i); // Outputs: 5, 4, 3, 2, 1 } }

Task

Complete the code so that it prints all numbers from 2 to 10 inclusive.

main.dart

main.dart

copy
12345
void main() { for (int i = 2; i <= 10; ___) { print(i); } }

Use an increment operator.

main.dart

main.dart

copy
12345
void main() { for (int i = 2; i <= 10; i++) { print(i); } }
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 4. Hoofdstuk 5
some-alt