Dino Geek, try to help you

How to use (for while) loops in Python?


Python makes use of two main types of loops: ‘For’ loops and ‘While’ loops.

1. For loop:
The For loop in Python is used to iterate over a sequence (like a list, tuple, string, or range) or other iterable objects in Python.

Syntax:
```
for variable in sequence: # statements
```

Example:
```
fruits = [‘apple’, ‘banana’, ‘cherry’]
for fruit in fruits: print(fruit)
```

This will output each fruit name in the ‘fruits’ list.

1. While loop:
The While loop in Python is used to execute a block of statements repeatedly until a given condition is satisfied.

Syntax:
```
while condition: # statements
```
Example:
```
count = 1
while count <= 5: print(count) count += 1
```

This will output the numbers 1-5. The While loop continues to iterate while the ‘count’ variable is less than or equal to 5.

Note: It’s necessary to increment ‘count’ to avoid an infinite loop.
Remember to keep track of your conditions in while loops, as they can potentially result in infinite loops if conditions are not met correctly.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use