Dec 16, 2011

The break and the endless cycle


We saw recently the for loop , and found that its structure was as follows:
for (start, end; increase)
What happens if we no beginning or end? Then we get an infinite loop, like this:
for (;;)
And how do you stop? For a break, like this:
for (;;)
{
break;
}
And this for me to use? For the idea is to repeat the instructions until the user wants to, ie:
 # Include <stdio.h>
 # Include <conio.h>
 int main ()
 {
   char end = 0;
   for (;;)
   {
     gotoxy (5, 5); printf ("I want to quit? (y / n):") scanf ("% c", & end);
     if (end == 'y')
       break;
     ClrScr ();
   }
 } 
I do not think I had mentioned that if within an if condition is only one instruction is not necessary to put keys, and also applies to the cycles.
If the user does not enter a 'y', the program never stops. Then we will see that the properties of aninfinite loop is very similar to the while loop to be discussed later.

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Premium Wordpress Themes