[Solved] What is a loops?
Lesson 1 of Kiddo course.
A loop is a concept in computer programming which is used to execute various commands repeatedly up to a desired number of times. This helps in having a clean code and saving up the time of writing redundant code.
For example:
I am using JavaScript programming language to showcase the example:
Let us assume, we are asked to write “Hello World” 4 times. We can write the following code:
console.log("Hello World"); console.log("Hello World"); console.log("Hello World"); console.log("Hello World");
This can be one way of approaching the problem, but you will notice that it is time taking to write same code multiple times, thus increasing the redundancy of the code. Therefore, we can write it in the following manner:
for (var i = 0; i < 4; i++) { console.log("Hello World"); }
You will notice that output from both the methods are the same, but length of code is lesser in the latter case. This is how loops make work of the programmers easier on a day-to-day basis
loop is statement which repeats a task.
@demo-learner A loop is used to reduce the steps if they have a pattern.
- 14 Forums
- 1,836 Topics
- 5,052 Posts
- 0 Online
- 1,078 Members