# P6.5 Python while Loop उदाहरणांसह

Source: https://ravindrabagale.com/mr/datascience/py06-python-for-loops-and-while-loops-explained-with-examples/p6-5-python-while-loop-with-examples.html
Language: mr (Marathi with English technical terms)

हे का शिकायचं?

किती फेऱ्या लागतील ते आधी माहीत नसतं — बचत goal किती महिन्यांत पूर्ण होईल?

हे काय आहे?

while condition: — condition True आहे तोपर्यंत loop चालत राहतो. आत condition बदलली नाही तर loop कधीच थांबत नाही.

कसं करायचं?

Step 1. Starting value ठरवा.
Step 2. while condition: लिहा.
Step 3. आत value बदला म्हणजे loop थांबेल.

उदाहरण A: बचत goal ला किती महिने

```python
saved = 0
months = 0
while saved < 2000:
    saved += 300
    months += 1
print(months, "months, saved €", saved)
```

Output:

```text
7 months, saved € 2100
```

याचा अर्थ: Goal पूर्ण होईपर्यंत दर महिन्याला बचत जोडली आणि महिने मोजले.

उदाहरण B: Stock संपत जातो

```python
stock = 150
day = 0
while stock > 0:
    day += 1
    stock -= 40
print("Out of stock on day", day)
```

Output:

```text
Out of stock on day 4
```

याचा अर्थ: Stock शून्य होईपर्यंत loop चालला.

रवींद्र बागले यांची tip

Jupyter सतत चालूच राहिलं तर तुमची while condition कधी False होत नाही. ■ stop button दाबा (kernel interrupt) आणि loop मधला बदल दुरुस्त करा.
