breaking the loop

vaibhav_89's Avatar
Go4Expert Member
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 shabbir; 24Oct2007 at 09:30.. Reason: Code block
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.
vaibhav_89's Avatar
Go4Expert Member
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 shabbir; 24Oct2007 at 10:06.. Reason: Code block
vaibhav_89's Avatar
Go4Expert Member
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 shabbir; 24Oct2007 at 10:06.. Reason: Code block
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Do you read the replies or just copy paste the same thing over and over again.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Now its 5 times you have that smiley post where you did not read the reply as well.