0

About JavaScript

Please explain me about loops, and it's uses

20th Jul 2024, 4:13 PM
Soumyadip Parui
Soumyadip Parui - avatar
3 ответов
+ 1
I think this question was asked a lot of times, but works the same in js as in php, c, cpp, c#, and so on. for loop: (start, until, iterate) { do this block } while loop: (condition) { do this block; iterate } # if you forgot the iterator, you can create an infinite loop use for loop if you know how many times the code should run; # do this 13 times use while loop if you don't how many times the code should run; # ask the question until there is a "correct" answer before asking similar questions, please, look after it. maybe is already answered.... I hope this helps
20th Jul 2024, 4:48 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
0
It will be a tedious task to be writing the same code over and over within my program. What if I'm suppose to write it 5000 times. Wow.😳. Then i have got a lot to type. Oh ok. I now remember there is something called loops.😀 I heard its going to make the task easier for me. I don't have to type the same code many times. Why don't i type it once and tell the program how many times i want that code to run. Where do i start from? There are different types of loops. The “for loop”, “while loop”, “do while”. Which one do i use then? In this my case, since i know the number of times i want to run that particular code it would be appropriate to use the for loop rather than others though the others can also do the same task for me. If i don't know the number of times i want to run the code ahead of time, then it will be appropriate to use the while loop. In writing the for loop, i need a start value which is initialized once, an end value which will be a condition whch evaluates to true or false and an increment exp
21st Jul 2024, 9:18 AM
DESMOND YEBOAH
DESMOND YEBOAH - avatar
0
syntax:: // common for for (let i = 0; i < 10; i++) { } // common forEach ARRAY.forEach((element, index) => { }); // async for for ARRAYS for (let element of ARRAY) { } // do-while do { } while(i > 10) // while while(i < 10) { }
25th Jul 2024, 12:03 AM
exez
exez - avatar