1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

breaking the loop

Discussion in 'C' started by vaibhav_89, Oct 24, 2007.

  1. vaibhav_89

    vaibhav_89 New Member

    Joined:
    Oct 14, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    which function can i use in c/c++ so that as soon as i press a certain character then the loop breaks away goes into the next loop.
    for example:
    start:
    Code:
    for(..;..;..;) /*loop1*/
    {....;
    .....; /*now if i press any 'a' when loop 1 is excuting then it should go to loop 2
    .....;
    }
    goto strat;
    if(getch()=='a') /* loop 2*/
    for (..;..;..)
    ...;
    ...;
    ..;
     
    Last edited by a moderator: Oct 24, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    If you want the loop to break immediately its not about having an input mechanism but it should be done on different thread.

    Something like when a loop is executed it checks of some variable and that variable is set via different thread which is meant for the input and thats the only way of doing it. If you have the input mechanism in the loop itself it will not proceed further till you input the value.
     
  3. vaibhav_89

    vaibhav_89 New Member

    Joined:
    Oct 14, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    i want to run the loop till a character 'a' is inputted.as soon as 'a' is typed i want the previous loop to break up and go to a new loop
    for example:
    start:
    Code:
    for(..;..;..;) /*loop1*/
    {....;
    .....; /*now if i press any 'a' when loop 1 is excuting then it should go to loop 2
    .....;
    }
    goto strat;
    /*loop 2 should strat if 'a' is typed when loop 1 is running*/
    if(getch()=='a') /* loop 2*/
    for (..;..;..)
    ...;
    ...;
    ..;
     
    Last edited by a moderator: Oct 24, 2007
  4. vaibhav_89

    vaibhav_89 New Member

    Joined:
    Oct 14, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    i want to run the loop till a character 'a' is inputted.as soon as 'a' is typed i want the previous loop to break up and go to a new loop
    for example:
    start:
    Code:
    for(..;..;..;) /*loop1*/
    {....;
    .....; /*now if i press any 'a' when loop 1 is excuting then it should go to loop 2
    .....;
    }
    goto strat;
    /*loop 2 should strat if 'a' is typed when loop 1 is running*/
    if(getch()=='a') /* loop 2*/
    for (..;..;..)
    ...;
    ...;
    ..;
     
    Last edited by a moderator: Oct 24, 2007
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Do you read the replies or just copy paste the same thing over and over again.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Now its 5 times you have that smiley post where you did not read the reply as well.
     

Share This Page