Why this program take a second to read the input from the second switch(sw2)

when we press switch 1 then seven segment display is run(0 to 9 continuously),
after that when we press the second switch(sw2) {for a second} then process stops on that digit when we press switch(sw2);
then why this program take a second to get the input from switch (sw2)?

code :-

int sw1 = 13;
int sw2 = 5;
int l1 = 12;
int l2 = 11;
int l3 = 10;
int l4 = 9;
int l5 = 8;
int l6 = 7;
int l7 = 6;
int madhe1 = 0;
int madhe2 = 0;
int thamba() {
  madhe2 = digitalRead(sw2);
  if (madhe2 == 0)
  {

    while (1)
    {
      madhe1 = digitalRead(sw1);
      if (madhe1 == 0)
      {
        return 0;
      }
    }
  }
}

void setup() {
  pinMode(sw1, INPUT);
  pinMode(sw2, INPUT);
  pinMode(l1, OUTPUT);
  pinMode(l2, OUTPUT);
  pinMode(l3, OUTPUT);
  pinMode(l4, OUTPUT);         //0
  pinMode(l5, OUTPUT);
  pinMode(l6, OUTPUT);
  pinMode(l7, OUTPUT);


}

void loop() {
  digitalWrite(l1, HIGH);
  digitalWrite(l2, HIGH);
  digitalWrite(l3, HIGH);
  digitalWrite(l4, HIGH);
  digitalWrite(l5, HIGH);
  digitalWrite(l6, HIGH);
  digitalWrite(l7, HIGH);

  
  madhe1 = digitalRead(sw1);
  if (madhe1 == 0)
  {
  up:

    thamba();

    digitalWrite(l1, LOW);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);
    digitalWrite(l5, LOW);
    digitalWrite(l6, LOW);
    digitalWrite(l7, HIGH);
    delay(1000);

    thamba();
    digitalWrite(l1, HIGH);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, HIGH);      //1
    digitalWrite(l5, HIGH);
    digitalWrite(l6, HIGH);
    digitalWrite(l7, HIGH);

    delay(1000);

    thamba();
    digitalWrite(l1, LOW);
    digitalWrite(l2, LOW);
    digitalWrite(l3, HIGH);
    digitalWrite(l4, LOW);
    digitalWrite(l5, LOW);         //2
    digitalWrite(l6, HIGH);
    digitalWrite(l7, LOW);
    delay(1000);
    thamba();
    digitalWrite(l1, LOW);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);           //3
    digitalWrite(l5, HIGH);
    digitalWrite(l6, HIGH);
    digitalWrite(l7, LOW);
    delay(1000);
    thamba();
    digitalWrite(l1, HIGH);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, HIGH);
    digitalWrite(l5, HIGH);
    digitalWrite(l6, LOW);
    digitalWrite(l7, LOW);
    delay(1000);
    thamba();
    digitalWrite(l1, LOW);
    digitalWrite(l2, HIGH);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);
    digitalWrite(l5, HIGH);
    digitalWrite(l6, LOW);
    digitalWrite(l7, LOW);
    delay(1000);
    thamba();
    digitalWrite(l1, LOW);
    digitalWrite(l2, HIGH);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);
    digitalWrite(l5, LOW);
    digitalWrite(l6, LOW);
    digitalWrite(l7, LOW);
    delay(1000);
    thamba();
    digitalWrite(l1, LOW);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, HIGH);
    digitalWrite(l5, HIGH);
    digitalWrite(l6, HIGH);
    digitalWrite(l7, HIGH);
    delay(1000);
    thamba();
    digitalWrite(l1, LOW);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);
    digitalWrite(l5, LOW);
    digitalWrite(l6, LOW);
    digitalWrite(l7, LOW);
    delay(1000);
    digitalWrite(l1, LOW);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);
    digitalWrite(l5, HIGH);
    digitalWrite(l6, LOW);
    digitalWrite(l7, LOW);
    delay(1000);
    thamba();
    goto up;

  }
}

Your sketch is full of one second delay() calls. Could that have something to do with it?

because of

all delays are about running digits in seven segment display

It doesn't matter, what the delay for.
But until the code in the delay() - it can't read your switch

all delays are about running digits in seven segment display
that's why I use delay (1000);

at the time of reading there is no delay in the code

then you need to try to press the button exactly at the moment when the program reads the switch :slight_smile:

True, but you could press that second switch at any time, that means the code won't necessarily be looking at the switch when you press it. It will only look at the switch when all the delays are finished and the code that looks at the switch is got to.

The delay you experience is due to what delays are left in the previous display finishing. Code is a sequential thing and only takes effect when the program gets to look at your switch. That is why you experience a delay which will last as long as your code takes while it gets round to looking at the switch.

We get asked about this problem several times a day. The way round it is to remove all delays in your code and implement a state machine. The blink without delay example In the IDE is an example of this technique.

so what is the solution over this program
please suggest

Read my post.

Never never ever use a goto in a C program. Is shows off that you do not have a clue about how functions work, there is normally no need for one. Don't do it, learn about how functions work.

Calling a function whose name is the same as the function name is called recursion. This is a very advanced technique which you are not using correctly. Using it the way you do will lead to your code going wrong and even crashing eventually.
Because the processor will run out of memory.

Is this an assignment you have been given?

appreciating you @Grumpy_Mike,
thank you for your valuable suggestion.
.
.
.
and yes this is assignment for myself but eventually this isn't working as expected.

Well it is working as expected, it is just not working how you expected.

As I said the code is quite simply a mess. Here are two links that explain how the Blink without delay works, and how you can write your program to make it work.

http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

Or Robin2's several things at once
http://forum.arduino.cc/index.php?topic=223286.0

It would also be good if you learned about arrays as well.
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

It looks so much like, "int 14 = 9".

I recommend using much more legible and self explanatory names.

It won't be long before you spend several hours of tearing your hair out over a simple typo error.