๐๐ข๐ข๐ฃ๐ฆ ๐๐ก๐ ๐๐จ๐ก๐๐ง๐๐ข๐ก๐ฆ ๐๐ก ๐๐๐ฉ๐๐ฆ๐๐ฅ๐๐ฃ๐ง
Loops repeat code for you.
Use a for loop when you know the count. If the condition is false, the loop does not run.
A while loop checks the condition first. Think of taking a bus. You check your money first. No money means no ride. The loop never starts.
A do-while loop checks the condition last. Think of an ATM. You withdraw money first. You ask if you want more after the task. You always use the machine at least once.
Functions are code blocks for one task. Stop writing the same code multiple times. Put the code in a function. Call it when you need it.
Functions provide these benefits:
- Reuse code.
- Fix bugs faster.
- Remove duplicate code.
- Improve readability.
JavaScript uses three function types:
- Normal Functions.
- Function Expressions.
- Arrow Functions.
Source: https://www.w3schools.com/js/js_functions.asp Optional learning community: https://dev.to/raja_b_0c9d242e2c26cf063b/loop-for-and-do-while-funtion-4629