Notifications
Clear all

[Solved] What is a loops?

4 Posts
3 Users
5 Likes
499 Views
1
Topic starter

Lesson 1 of Kiddo course.

2 Answers
2

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

demo.learner demo.learner Topic starter 04/03/2023 4:47 pm

@akshajsrivastava Thanks for the wonderful answer.

2
Topic starter

loop is statement which repeats a task.

Test user Test user 02/03/2023 5:01 pm

@demo-learner A loop is used to reduce the steps if they have a pattern.

Share: