7.1 循环goto

Posted: March 25, 2011 in C++

/*关键字goto实现循环:
应该避免使用goto, 因为其可以无条件的跳转到源代码的任何位置, 容易造成语句混乱, 质量低下,和无法阅读.
*/

#include <iostream>
using namespace std;

void main()
{
            int counter=0;

            cout<<“It’s goto looping.”<<endl;
loop:
            if(counter<5)
            {
                        cout<<counter<<endl;
                        counter++;
                        goto loop;
            }

            cout<<“looping finished.”<<endl;

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s