Convert to for loops?

So i have this code a 3 by 4 keypad. And i want to change it into a for loop. But i've a hard time understanding how i should do so.

The code is using the buttons 1,2,4 and 5 only.
Just wondering if someone could give a hint as to what i should do!

int col1 = 3;
int col2 = 6;

int row1 = 4;
int row2 = 2;

int reading_row1 = 0; 
int reading_row2 = 0;

int pin1 = 8;
int pin2 = 9;
int pin3 = 10;
int pin4 = 11;

void setup()
{
  Serial.begin(9600);
  pinMode(row1, INPUT_PULLUP); 
  pinMode(col1, OUTPUT);
  pinMode(row2, INPUT_PULLUP);
  pinMode(col2, OUTPUT);


  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  digitalWrite(col1, HIGH);
  digitalWrite(col2, HIGH);
  //digitalWrite(col3, HIGH);
}
void loop()
{



  digitalWrite(col1, HIGH);  
  digitalWrite(col2, LOW);

  reading_row1 = digitalRead(row1); 
  reading_row2 = digitalRead(row2);

  if (reading_row1 == LOW)  
  {
    Serial.println("2");
    digitalWrite(9, LOW); 
    digitalWrite(8, LOW);
    digitalWrite(10, HIGH); 
    digitalWrite(11, LOW);
  }
  else if (reading_row2 == LOW) 
  {
    Serial.println("5");
    digitalWrite(9, HIGH); 
    digitalWrite(8, LOW);
    digitalWrite(10, LOW);
    digitalWrite(11, LOW);
  }

  digitalWrite(col1, LOW); 
  digitalWrite(col2, HIGH);

  reading_row1 = digitalRead(row1);
  reading_row2 = digitalRead(row2);

  if (reading_row1 == LOW)
  {
    Serial.println("1");
    digitalWrite(9, LOW);
    digitalWrite(8, HIGH);  
    digitalWrite(10, LOW);
    digitalWrite(11, LOW);


  }
  else if (reading_row2 == LOW)
  {
    Serial.println("4");
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
    digitalWrite(10, LOW);
    digitalWrite(11, HIGH);  
  }
}

It is unclear from your post WHY you would want to change it into a FOR loop. It is also unclear WHAT you want to change into a FOR loop. Yet, I will take a stab that you want to change the repeated lines digitalWrite() into a FOR loop, and will answer with that assumption. First, make an array of your pin numbers. Next, make an array of bit masks where each bit is a HIGH or LOW (1 or 0). Next, write a function including the FOR loop that when passed an index to the bit mask array, will iterate over the pin array and bits in the indexed bit mask. See

or

where I have example code.

You well you are right!!
But i cannot check your links?

Lexianlex:
You well you are right!!
But i cannot check your links?

I can't get the links to work, but I have removed the code from the links... They should work now if you copy and paste.

I recommend the Keypad library which will do all the work for you:

Sketch->Include Library->Manage Libraries...

Type "Keypad" in the "Filter your search..." box.

Scroll down to:
Keypad by Mark Stanley, Alexander Brevig

Click on it and then click on the "Install" button.