Skip to main content

break, continue, and pass in Python पायथन में, `ब्रेक`, ` कंटिन्यू`, और `पास`

In Python, `break`, `continue`, and `pass` are control flow statements used in for and while loops and conditional if-else.

पायथन में, `ब्रेक`, ` कंटिन्यू`, और `पास` नियंत्रण प्रवाह के कथन हैं जिनका उपयोग फॉर और व्हाइल लूप और कंडीशनल इफ-एल्स में किया जाता है।

1.) break statement:- It Exits the loop immediately, regardless of the iteration count or condition. It is commonly used to stop a loop when a certain condition is met.
1.) ब्रेक स्टेटमेंट:- यह पुनरावृत्ति गणना या स्थिति की परवाह किए बिना तुरंत लूप को समाप्त कर देता है। इसका उपयोग आमतौर पर एक निश्चित शर्त पूरी होने पर लूप को रोकने के लिए किया जाता है।

Syntax:-

 break

Example:-

for i in range(5):

  if i == 3:

     break

  print(i)

Output:-

0
1
2

2.) continue statement:- It skips the rest of the code inside the loop for the current iteration and moves to the next iteration. It is Useful when we want to skip certain conditions in the loop but continue iterating.
2.) कंटिन्यू कथन: - यह वर्तमान पुनरावृत्ति के लिए लूप के अंदर शेष कोड को छोड़ देता है और अगले पुनरावृत्ति पर चला जाता है। यह तब उपयोगी होता है जब हम लूप में कुछ शर्तों को छोड़ना चाहते हैं लेकिन पुनरावृत्ति जारी रखते हैं।

Syntax:-

  continue

Example:-

for i in range(5):

  if i == 3:

    continue

  print(i)

Output:-

0
1
2
4

3.) pass statement:- It does nothing. It's a placeholder that lets you define a code block syntactically but without any operation. It is Useful in places where syntactically, a statement is required but you don't want to execute any code yet for example during development of program.
3.) पास स्टेटमेंट:- यह कुछ नहीं करता है। यह एक प्लेसहोल्डर है जो आपको बिना किसी ऑपरेशन के कोड ब्लॉक को वाक्यात्मक रूप से परिभाषित करने देता है। यह उन जगहों पर उपयोगी है जहां वाक्यविन्यास की दृष्टि से, एक कथन की आवश्यकता होती है लेकिन आप अभी तक किसी भी कोड को निष्पादित नहीं करना चाहते हैं, उदाहरण के लिए प्रोग्राम के विकास के दौरान।

Syntax:-
  pass 

Example:-

for i in range(5):

  if i == 3:

    pass # Placeholder

  print(i)

Output:-

0
1
2
3
4

Comments

Popular posts from this blog

Filter function of python

filter function:-  Imagine we have a bunch of things, like a list of numbers, a collection of fruits, or any other group of items. Now, let's say we want to pick out only certain items from that group based on a specific condition. This is where the filter function comes in handy. Let's say we have a list of numbers, and we want to filter out only the even numbers. We define a condition-checking function that checks if a number is even. Then, we pass this function and the list of numbers to the filter function. It goes through each number, applies the condition-checking function, and keeps only the numbers that are even. Finally, it gives us a new list containing only the even numbers. def is_even(num):     return num % 2 == 0 numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] filtered_numbers = list(filter(is_even, numbers)) print(filtered_numbers) Output [2, 4, 6, 8, 10] We can also utilize lambda expressions to define filtering conditions directly within the filter function. nu...

The Python Interpreter पायथन इंटरप्रेटर

The Python interpreter is a program that executes Python code. It reads and interprets Python scripts or interactive commands, converting them into machine-readable bytecode for the computer to execute.The interpreter is a crucial component for running Python code, facilitating both learning and development processes. Users can interact with the interpreter in two primary modes: पायथन इंटरप्रेटर एक प्रोग्राम है जो पायथन कोड को निष्पादित करता है। यह पायथन स्क्रिप्ट या इंटरैक्टिव कमांड को पढ़ता है और व्याख्या करता है, उन्हें कंप्यूटर द्वारा निष्पादित करने के लिए मशीन-पठनीय बाइटकोड में परिवर्तित करता है। दुभाषिया पायथन कोड चलाने के लिए एक महत्वपूर्ण घटक है, जो सीखने और विकास दोनों प्रक्रियाओं को सुविधाजनक बनाता है। उपयोगकर्ता इंटरप्रेटर के साथ दो प्राथमिक मोड में बातचीत कर सकते हैं:- 1. Interactive Mode:- In this mode we can launch the Python interpreter in our terminal or command prompt without specifying a script.This mode allows us to enter Python commands and see immediate results...

Flow of execution of a python program पाइथन प्रोग्राम के निष्पादन का प्रवाह

Flow of execution represents a general outline of Python program execution. The specific flow can vary based on the program's structure, control flow statements (if, else, for, while), and function calls. निष्पादन का प्रवाह पायथन प्रोग्राम निष्पादन की एक सामान्य रूपरेखा का प्रतिनिधित्व करता है। विशिष्ट प्रवाह प्रोग्राम की संरचना, नियंत्रण प्रवाह विवरण (यदि, अन्यथा, के लिए, जबकि), और फ़ंक्शन कॉल के आधार पर भिन्न हो सकता है। 1.) Start: The program begins execution. 1.) प्रारंभ: प्रोग्राम का निष्पादन प्रारंभ होता है। 2.) Import Modules: If necessary, the program imports external modules or libraries. 2.) मॉड्यूल आयात करें: यदि आवश्यक हो, तो प्रोग्राम बाहरी मॉड्यूल या लाइब्रेरी आयात करता है। 3.) Define Functions: Any functions used in the program are defined. 3.) फंक्शन्स को परिभाषित करें: प्रोग्राम में उपयोग किए गए किसी भी फंक्शन को परिभाषित किया जाता है। 4.) Main Program: The main body of the program starts. 4.) मुख्य प्रोग्राम: प्रोग्राम का मुख्य भाग प्रारंभ होता है। 5.) Initializat...