Python Forum
While loop and If Statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While loop and If Statement
#2
Hello,
if "z" in testlist[index]
This line checks if character "z" is in the string "testlist[index]", not if the string is "z". So "pizza" will be True.
What you need instead is
if "z" == testlist[index]
You also don't need and index to iterate a list. You can simply do it like this:
my_list = ['a', 'b', 'c']
for item in my_list:
    print(item)
And instead of "continue", you will need a "break" when the condition is met.
Reply


Messages In This Thread
While loop and If Statement - by farzankh - Jan-27-2019, 05:43 PM
RE: While loop and If Statement - by j.crater - Jan-27-2019, 08:18 PM
RE: While loop and If Statement - by farzankh - Jan-27-2019, 09:36 PM
RE: While loop and If Statement - by stullis - Jan-27-2019, 10:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help converting int to str value in loop statement Jrvelandia 2 2,594 Feb-12-2018, 08:57 AM
Last Post: Jrvelandia
  if statement in for loop Danielk121 3 3,739 Nov-13-2017, 01:52 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020