Topic 11: JS use of 'while loop'

//Regular Lecture 16: 14 Oct 2022

// Topic 11: //*use of while loop*//


while(5==5){
    console.log("Hello") 
    break
}


// ptint 1 to 3

let t1 = 1
while(t1 <= 5){
    console.log(t1)
    t1 ++
}


// print 3 times hello

let t2 = 1
while(t2 <= 5){
    console.log("hello")
    t2 ++
}


//break with while loop: example 1

let t3 = 11
while(t3 <= 20){
    console.log(t3)
    if(t3 == 14){
        break       // prints 11,12,13,14 and then stop the loop
    }
    t3 ++
}


//break with while loop: example 2

let t4 = 21
while(t4 <= 30){
    console.log(t4)
    if(t4 == 25){
        break       // prints 21,22,23,24,25 and then stop the loop
    }
    t4 ++
}

टिप्पण्या