Having trouble understanding "scope"

I am completely new to C or C++, coming from python and js, and have never had to take scope into consideration before.
This code:

int n = 0;
int i = 5;
int k = 0;
void setup() {
  Serial.begin(9600);
  for(i=5; i<=13; i++){
    pinMode(n,OUTPUT);
  }
  
}

void loop() {
  int k = n;
  int i = 5;
  for(i=5; i<=13; i++){
    digitalWrite(i,LOW);
  }
  Serial.println(k);
  if ((k-128) > -1){
    digitalWrite(5,HIGH);
    int k = k-128;
  }
  Serial.println(k);
  if ((k-64) > -1){
    digitalWrite(6,HIGH);
    int k = k-64;
  }
  Serial.println(k);
  if ((k-32) > -1){
    digitalWrite(7,HIGH);
    int k = k-32;
  }
  Serial.println(k);
  if ((k-16) > -1){
    digitalWrite(8,HIGH);
    int k = k-16;
  }
  Serial.println(k);
  if ((k-8) > -1){
    digitalWrite(9,HIGH);
    int k = k-8;
  }
  Serial.println(k);
  if ((k-4) > -1){
    digitalWrite(10,HIGH);
    int k = k-4;
  }
  Serial.println(k);
  if ((k-2) > -1){
    digitalWrite(11,HIGH);
    int k = k-2;
  }
  Serial.println(k);
  if ((k-1) > -1){
    digitalWrite(12,HIGH);
  }
  n++;
  delay(1000);
  Serial.println("new");
}

LED's along my breadboard should create a "binary clock", so to speak, meaning after 1 second the first LED will come on [00000001], after 2 seconds only the second will be on [00000010] and after 3 the first two would be on [00000011], but every LED below the highest that should be on stays on. I put a delay after the for loop to turn them all off and confirmed that it is doing so. Currently, the program also writes to the serial monitor, outputting the current value being analysed, k, every time a comparison is made, and then outputs "new" after every second. This value of k is not changing:


even though I have attempted to take away the value its being compared against (eg k = k - 128). I have narrowed the problem down to the scope of the variable, but the official scope explanation was no help and I am stuck, could someone please explain how this works and maybe suggest a solution?

I am not pro, but I don't get why you are re-declaring the type

int k = k-4;

when you have defined it as global variable

int n = 0;
int i = 5;
int k = 0;

Also
https://playground.arduino.cc/Code/VariableScope

.