Important Notice:

Introduction to Loops

Introduction to Loops

24 views 1 min read

Introduction to Loops :-

Loop Python में एक Control Flow Statement (नियंत्रण प्रवाह कथन) है, जिसका उपयोग किसी statement या statements के समूह को बार-बार execute (दोहराकर निष्पादित) करने के लिए किया जाता है।

जब किसी program में एक ही काम को कई बार करना हो, तो उसी code को बार-बार लिखने के बजाय loop का उपयोग किया जाता है। इससे program का code short, simple और efficient बनता है।

उदाहरण के लिए, यदि हमें Hello को 5 बार print करना है, तो बिना loop के हमें print() statement को 5 बार लिखना पड़ेगा। Loop की सहायता से इसे कम code में किया जा सकता है।

Python में loop के अंदर लिखे code को Indentation (रिक्त स्थान) देना आवश्यक होता है। Indentation यह बताता है कि कौन-सा statement loop block के अंदर है। सामान्यतः 4 spaces का indentation प्रयोग किया जाता है।

English

A Loop is a control flow statement in Python that is used to execute a statement or a group of statements repeatedly.

When the same task needs to be performed multiple times in a program, a loop can be used instead of writing the same code again and again. It makes the program short, simple, and efficient.

For example, if we want to print Hello five times, we can use a loop instead of writing the print() statement five times.

In Python, the code written inside a loop must be given Indentation (spaces). Indentation indicates which statements are part of the loop block. Generally, 4 spaces are used for indentation.

Python mainly has two types of loops:

  1. for Loop
  2. while Loop

Related Notes