For loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

For loop

how it works

6th Oct 2018, 9:17 PM
Chandra Prakash
3 Answers
+ 4
Chandra Prakash, Here explained in javascript: for (let i=0; i<=10; i++){ console.log(i); } i - is created to be a local variable, Therefore using let, it can only be declared once to encolse conflicts. Let - Can only be declared once. i=0 - We give the variable i a value of 0. i<=10 - Loop variable i till it is equal to 10. i++ - Increment the value by 1 every iteration for ( local variable i= value 0; // let i=0; increment i till equals <= value 10; // i<=10; Increment i by ++ 1 every iteration; //_ i++ ) {} Hope this helps👍
6th Oct 2018, 9:53 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
0
words = ["hello", "world"] counter =0 max_index = len(words)-1 while counter <= max_index: word = words[counter] print(word +"i") counter = counter +1 output: hello! world! how it works in while loop?? confusing
6th Oct 2018, 10:06 PM
Chandra Prakash