7 Respostas
+ 7
Joël Northon ,
python has 2 loop types:
> for loop
> while loop
for both of them you can find helpful descriptions and exercises in the various python tutorials.
may be you should start with `introduction to python`.
+ 5
Joël Northon ,
please keep in mind that sololearn is a *self-learner* platform, we can use the tutorials to learn from, and also the exedcises to practice.
the tutorial `introduction to python` is covering *while loops*, so just start learning and practicing.
https://www.sololearn.com/learn/courses/python-introduction
if you encounter a specific coding problem, you can place a question here.
+ 3
tacobell = True
while tacobell:
print("poo")
https://sololearn.com/compiler-playground/cKT5M3V9uysF/?ref=app
+ 2
In Python, you can use a while loop to repeatedly execute a block of code as long as a condition is true
while condition:
# Code to execute while condition is True
# This code will repeat until the condition becomes False
using a while loop to count from 1 to 5:
counter = 1
while counter <= 5:
print(counter)
counter += 1 # Increment the counter by 1 in each iteration
```
- We initialize a variable `counter` to 1 outside the loop.
- The while loop continues as long as the condition `counter <= 5` is true.
- Inside the loop, we print the current value of `counter` and then increment it by 1 using `counter += 1`.
- The loop repeats until `counter` is no longer less than or equal to 5.
This will output:
1
2
3
4
5
make sure that the condition in the while loop will eventually become false otherwise, the loop will run indefinitely, causing a program to hang.
+ 1
This is an infinity loop
+ 1
Joël Northon Correct, do you have any other questions about while loops?
0
While loop