Code:
#library import / set tkinter as tk for shorter calls
from tkinter import *
import tkinter as tk
#create window inc. title and size
root = Tk()
root.title("chessboard with coordinates")
root.geometry('642x570')
#function for coordinates
def coordinates(x,y):
    print(x,y)
for i in range(8):
    if i%2==0:
        for k in range(8):
            if k%2 ==0:
                tk.Button(root, width=10, height=4, bg="black",command=lambda x=i,y=k: coordinates(x,y)).grid(row=i,column=k)
            else:
                tk.Button(root, width=10, height=4, bg="white",command=lambda x=i,y=k: coordinates(x,y)).grid(row=i,column=k)
    else:
        for k in range(8):
            if k%2 ==0:
                tk.Button(root, width=10, height=4, bg="white",command=lambda x=i,y=k: coordinates(x,y)).grid(row=i,column=k)
            else:
                tk.Button(root, width=10, height=4, bg="black",command=lambda x=i,y=k: coordinates(x,y)).grid(row=i,column=k)
root.mainloop()
Can someone explain how these loops work in this code? Would be very grateful, I'm a little confused right now.
 
     
    