Python Forum
My if and while loop statements aren't working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My if and while loop statements aren't working
#8
because once counter is incremented to 5 in some of the previous iterations, it will not enter the loop at all. that is also the reason while you don't need to check counter<5 in lines 9 and 12.

 
counter = 0
while counter<5:
    print(counter)
    counter += 1
Output:
0 1 2 3 4
eventually you can change it to while<=5

counter = 0
while counter<=5:
    print(counter)
    counter += 1
Output:
0 1 2 3 4 5
Reply


Messages In This Thread
RE: My if and while loop statements aren't working - by buran - Oct-21-2017, 07:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  while loop not working-I am using sublime text editor mma_python 4 1,318 Feb-05-2023, 06:26 PM
Last Post: deanhystad
  Multiple Loop Statements in a Variable Dexty 1 1,324 May-23-2022, 08:53 AM
Last Post: bowlofred
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,647 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  Too many if statements working as "tags" zeek 3 2,109 Sep-20-2021, 05:22 PM
Last Post: deanhystad
  Parameters aren't seen inside function Sancho_Pansa 8 3,185 Oct-27-2020, 07:52 AM
Last Post: Sancho_Pansa
  Why is the while loop not working? mcoliver88 5 3,316 Aug-18-2020, 03:27 PM
Last Post: deanhystad
  Infinite loop not working pmp2 2 1,766 Aug-18-2020, 12:27 PM
Last Post: deanhystad
  Loop not working Nonameface 8 3,179 Jul-19-2020, 12:27 PM
Last Post: snippsat
  Unable to combine print statements in for loop adeana 2 2,132 Jun-12-2020, 05:08 PM
Last Post: adeana
  for loop script over telnet in Python 3.5 is not working abhijithd123 1 3,009 May-10-2020, 03:22 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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