Administrator
发布于 2024-04-28 / 16 阅读
0
0

typescript-循环和条件判断

for循环

// 普通for
for(let i=1;i<= 10; i++){
    console.log('点赞'+i+'次')
}
// while
let i = 1;while(i <= 10){
    console.log('点赞'+i+'次');
    i++;
}
let names:string[] = ['a0' ,'b0' ,'c0']

for(const i in names){
    console.log(i+" : "+names[i])
}

for(const name of names){
    console.log(name)
}

条件判断

if
let a = 100;

    if (a == 100) {
        console.log(a)
    }
switch
let a = 100;

switch(a){
    case 100:
    console.log("good")
    break
    default:break
}


评论