7章4节break和continue

来源:互联网 发布:罗马圣保罗大教堂知乎 编辑:程序博客网 时间:2024/05/18 20:48

#include <iostream>
int main ()
{
 using namespace std;
 typedef unsigned long ULONG;

 ULONG small,large,skip,target;

 const unsigned short MAXSMALL=65535;

 cout << "enter a small number: " ;
 cin >> small;
 cout << "enter a large number: ";
 cin >> large;
 cout <<"enter a skip number: ";
 cin >> skip;
 cout << "enter a target number: ";
 cin >> target;

 cout << " /n";

 // set up 2 stop conditions for the loop
 while (small<large &&  small<MAXSMALL)
 {
  small++;
  
  if(small%skip ==0) //skip the decrement?
  {
   cout << "skipping on " << small << endl;
   continue;
  }
  
  if(large==target) //exact match for the target?
  {
   cout << "Target reached ";
   break;
  }

  large-=2;
 }
       
 
      cout<<"/nsmall " << small << " large " << large << endl;
   return 0;
}

原创粉丝点击