Python continue with while [closed]

2024/11/7 22:32:47

There seems to be some serious problem with continue in Python: for eg:

for i  in range(1,10):if i % 2 == 0:continueprint i

works as intended, but

i = 0while(i < 10):if i %2 == 0:   continuei += 1print i

the while loop never terminates!

Answer

Your i is never incremented in the second snippet. Remove the continue.

i = 0
while(i < 10):if i %2 == 0:   # i == 0; continue without increment the value of i <-- stuck here!continuei += 1print i
https://en.xdnf.cn/q/120686.html

Related Q&A

Create MySQL database with python [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Basic Python repetition exercise

I was trying to learn Python when I came upon this question. I am not asking for you to answer the question for me, I just need some help. Note: I am only allowed to use loops and if statements etc. No…

Python 3.3 socket programming error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.Questions asking for code must demonstrate a minimal understanding of the problem being solved. Incl…

ValueError: math domain error

I wrote this codedef partE():e = 3 * 10 // 3 + 10 % 3print("e).", e)partE()and python comes back with this error message when I try to run it. I do not understand why. Can someone please expl…

how to access objects in python with for loop in different files

This is my file1.json: {"count": 1,"next": null,"previous": null,"results": [{"id": 5883,"url": "https://some.api.com/api/ipam/ip-addres…

multiplicative digital root of a number using loops

I need to find the multiplicative digital root of a number in python using only loops.something that does the same as the below code but using loops:print("multiplicative digital root of a number …

How to access key values in a json files dictionaries with python

I have a script that pulls json data from an api, and I want it to then after pulling said data, decode and pick which tags to store into a db. Right now I just need to get the script to return specifi…

How to use sin(x) and cos(x) functions with eval

I need a program which can make graphs by matplotlib with functions I write in the console. But it doesnt work with trigonometric functions. The code I already wrote is:from numpy import linspace impo…

python - whats the difference between = and ==? [duplicate]

This question already has answers here:What do the symbols "=" and "==" mean in python? When is each used?(5 answers)Closed 5 years ago.I wonder know whats the difference between …

Sorting images by dates into a list from a dictionary

I know I asked this before, but Im still not sure why I just get an empty list when I test thisdef sorted_images(image_dict): (dict) -> list of strGiven an image dictionary return a list of the file…