+ 1
For loop
how it works
3 Respostas
+ 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👍
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