Skip to main content

for loop, for in loop, for of loop in javascript

 here in this blog we are going to work with the 

  1. for loop
  2. for in loop 
  3. for of  loop

so here are the following codes as follows


//for loop in javascript
for (let i=0;i<5;i++){console.log(i)}
// program to add first natural numbers
let sum=0
let n = prompt("enter the value of n")
n= Number.parseInt(n)
for(let i=0;i<n;i++)//here we are using let so the value is only valid inside the curly brackets only but when we work with var instead of let than it becomes global and outside also i value can be obtained
{sum += (i+1)}
console.log("the sum of "+ n + " natural numbers is" + sum )


//for in loop in javascript
// let obj = {
//   sabih:99,
//   anwar:98,
//   shayaan:100,
//   ghufrana:23,
//   rizwana:66
// }
// for(let a in obj){console.log("marks of "+ a+" are "+obj[a])}


// // for of loop in javascript it mainly works in arrays
// for(let b of "shayaan"){console.log(b)}

Comments

Popular posts from this blog

How to add the treeview numbers to get the grand total in tkinter entry box

 in this blog we are going to know about the adding of the integers in the treeview and get the total in the entry box of tkinter so here is the image first so the coding to do such things are here as follow but here is the condition that pls make assured that the state of entry box is disabled.......      for child in my_tree1 . get_children ():         e2l . config ( state = "normal" )         b1 += float ( my_tree1 . item ( child , "values" )[ 3 ])         var2 . set ( b1 )         e2l . config ( state = "disable" )      l2l = Label ( ento , text = "Purnea-2" , width = 8 )      l2l . grid ( row = 0 , column = 1 )     e2l = Entry ( ento , textvariable = var2 , state = "disable" , width = 8 )     e2l . grid ( row = 1 , column = 1 )