+ 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
6 ответов
+ 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.
+ 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
+ 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
+ 2
Yeah I am using Pycharm