Python Forum
Change the varaible in For Loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change the varaible in For Loop
#1
Hello,
I have a very simple problem:
I am trying to increase the i in for loop like that:
1 2
4 5
3 4
6 7
5 6
8 9
One step I am increasing the i with +3 and the other step I am decreasing the i with -1
for i in range(1,number_of_qubit-2):
       print(i,i+1)
       i=i+3
       print(i,i+1)
       i=i-1
However I am getting this result:
1 2
4 5
2 3
5 6
3 4
6 7
4 5
7 8
Why am I seeing 2 and 3 instead of 4 and 5 ? How can I fix this problem
Reply


Messages In This Thread
Change the varaible in For Loop - by quest - Aug-13-2021, 02:23 PM
RE: Change the varaible in For Loop - by perfringo - Aug-13-2021, 02:56 PM
RE: Change the varaible in For Loop - by deanhystad - Aug-13-2021, 03:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Change variable value during a while loop? penahuse 2 4,056 Nov-15-2020, 11:53 PM
Last Post: penahuse
  (Python help) Change in logic not breaking 'while' loop? btcg2807 1 1,891 Sep-18-2019, 09:43 AM
Last Post: Larz60+
  change to loop amirliker 3 2,366 Jun-06-2019, 01:08 PM
Last Post: heiner55
  Call a varaible from class in the parent class Clement_2000 1 2,182 May-09-2019, 11:14 PM
Last Post: michalmonday
  change array column values without loop khalidreemy 2 3,771 May-05-2019, 09:05 AM
Last Post: DeaD_EyE
  Code Change Help: Infinite Loop Error bindulam 2 2,246 Mar-10-2019, 11:15 PM
Last Post: hshivaraj
  How to change from printFacts ( ) to return a list & Loop over list when writing CSV Ivan1 14 8,291 Aug-30-2017, 12:14 PM
Last Post: metulburr
  Timestamp doesn't change with each loop lwhistler 2 6,758 Aug-23-2017, 06:58 PM
Last Post: bowen73
  Loop thru textfile, change 3 variables for every line herbertioz 11 9,123 Nov-10-2016, 04:56 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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