+ 1

How to follow a code of for loop and see changing of variables?

I try to follow code but it's very hard to see how to variables getting changed

4th Aug 2021, 5:12 AM
Idoredid123
Idoredid123 - avatar
6 Respuestas
+ 5
Idoredid123 , here is a simple example. as you have not mentioned a programming language i have used python: (you can copy and paste the code to see what happens. if you not wanted to get all outputs but step by step, you can add an input() to temporarily interrupt the program flow. to continue just press return key) lst = [1, 3, 7, 0, 4] # creating y list of numbers for num in lst: # for loop header print("variable num is now: ", num) # print the content of loop variable # or use this way: print(f"{num=}") input() # temporarily interrupt the program flow ▪︎ a more professional way would be to use a debug mode (stepping line by line or at breakpoints), that allows you to see content of all variables without printing statement.
4th Aug 2021, 6:00 AM
Lothar
Lothar - avatar
+ 3
Alright I will use the advices thank you guys! Giorgos D NotHuman Lothar
4th Aug 2021, 6:45 AM
Idoredid123
Idoredid123 - avatar
+ 2
print to csv and use excel or save into arrays and visualize with matplotlib if you are working with python. Print to console if there isn't much variables
4th Aug 2021, 5:18 AM
▬▬▬
▬▬▬ - avatar
+ 2
If you are programming in an IDE you can benefit a lot from using a debugger, it lets you stop the execution of your program and proceed step by step while looking at the values of variables
4th Aug 2021, 6:15 AM
Giorgos
+ 2
Yeah I am using Pycharm
4th Aug 2021, 6:43 AM
Idoredid123
Idoredid123 - avatar
+ 2
Lothar Yeah I use Python as well
4th Aug 2021, 6:44 AM
Idoredid123
Idoredid123 - avatar