zoukankan      html  css  js  c++  java
  • 第七章 循环语句 简单

    /*
    // 1 循环语句的老祖宗Goto语句
    #include <iostream>
    using namespace std;
    int main()
    {
         int i= 1;
    	 if(i > 10){
    	     //goto yes;
    	 }
    	 cout<<"*"<<i<<endl;
    	 i++;
    	 //goto yes;
    	 cout<<"程序结束";
    	 cout<<"********\n";
    yes:;
    	 return 0;
    }
    */
    
    
    /*
    // 2 while语句
    #include <iostream>
    using namespace std;
    int main()
    {
        int i=1;
    	while(i < 10)
    	{
    	    cout<<"i:"<<i<<endl;
    		i++;
    	}
    	return 0;
    }
    */
    
    
    /*
    // 3 while语句的其它用法
    #include <iostream>
    using namespace std;
    int main()
    {
    	int number, dot=1;
    	cout<<"请问你想看几次:"<<endl;
    	cin>>number;
    	while(dot <= number)
    	{
    	    cout<<"问君能有几多愁,恰似一江春水向东流"<<endl;
    		dot++;
    	}
    	cout<<"程序运行结束"<<endl;
    	
    
        return 0;
    }
    
    */
    
    /*
    // 4 continue和break语句
    #include <iostream>
    using namespace std;
    int main()
    {
    	int i=0;
    	int b = 10;
    	while(i < b )
    	{
    		i++;
    		if(i == 8){
    		    cout<<"这里进行跳出while循环"<<endl;
    			break;
    		}
    		if(i==2){
    		   cout<<"这里只是跳出本次循环2"<<endl;
    		   continue;
    		}
    		
    		cout<<"i的值为:"<<i<<endl;
    	}
        return 0;
    }
    */
    
    /*
    // 6 do...while循环
    #include <iostream>
    using namespace std;
    int main()
    {
    	int number;
    	cout<<"请问您要看几次:"<<endl;
    	cin>>number;
    	int dot=0;
    	do{
    		 cout<<"这是第"<<number<<"次循环"<<endl;
    	     dot ++;
    	}while(dot <  number);
        return 0;
    }
    */
    
    /*
    //7 for循环
    #include <iostream>
    using namespace std;
    int main()
    {
    	int number, dot=0;
    	cout<<"请问您要看几次:"<<endl;
    	cin>>number;
    	for(int i=number; i>0; i--)
    	{
    	   cout<<"这是第"<<i<<"次操作"<<endl;
    	}
    
        return 0;
    }
    */
    
    //8 灵活的for循环
    #include <iostream>
    using namespace std;
    int main()
    {
    	for(int i=0, x=0,y=0; x<= 3; i++,x++,y++)
    	{
    	    cout<<"i="<<i<<", x="<<x<<", y="<<y<<endl;
    	}
        return 0;
    }
    

      

  • 相关阅读:
    设计模式-状态模式(25)
    设计模式-访问者模式(24)
    设计模式-观察者模式(22)
    设计模式-中介者模式(21)
    设计模式-行为型模式小结(20)
    设计模式-迭代器模式(19)
    Tomcat安装
    MySQL单表查询
    MySQL表操作
    MySQL表的完整性约束
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2552903.html
Copyright © 2011-2022 走看看