LOOPS

LOOPS

Loops are a fundamental concept in programming and they're used in TypeScript as well. Here are the basic types of loops in TypeScript:

  1. For Loop: This is the most common type of loop. It repeats a block of code a specific number of times.

for (let i = 0; i < 5; i++) {
  console.log(i); // This will print numbers 0 through 4
}
        

  1. While Loop: This loop continues to execute a block of code as long as a certain condition is true.

let i = 0;
while (i < 5) {
  console.log(i); // This will print numbers 0 through 4
  i++;
}
        

  1. Do-While Loop: This is similar to the while loop, but it checks the condition after executing the block of code. This means the block of code will always be executed at least once.

let i = 0;
do {
  console.log(i); // This will print numbers 0 through 4
  i++;
} while (i < 5);
        

  1. For-of Loop: This loop is used to iterate over the elements of an array or other iterable object.

let array = [1, 2, 3, 4, 5];
for (let value of array) {
  console.log(value); // This will print numbers 1 through 5
}
        


要查看或添加评论,请登录

Sultan Ahmed的更多文章

  • Alhamdulillah! Successfully Cleared Quarter 2

    Alhamdulillah! Successfully Cleared Quarter 2

    Alhamdulillah! Successfully Cleared Quarter 2 This journey has been an incredible learning experience, and I'm grateful…

  • Web & Media Agency Expands into E-

    Web & Media Agency Expands into E-

    We are thrilled to announce the launch of our new E-Commerce Store, leveraging our expertise in web development…

  • TypeScript Tuples

    TypeScript Tuples

    Tuples in TypeScript are essentially arrays with a fixed length and predetermined types for each element at each index.…

社区洞察

其他会员也浏览了