#include "iostream" /** *if for while *created by tengxign on 2017.1.10 */ using namespace std; int main(){ int a = 10; int b = 9; //if else语句 if(a>b)cout<<"a>b"; else if(a == b)cout<<"a==b"; else cout<<"a<b"<<endl; //switch语句 switch(a){ case 1: cout<<"a==1"; break; case 2: cout<<"a==2"; break; case 3: cout<<"a==3"; break; default: cout<<"a is not (1,2,3)"; break; } cout<<endl; //for for(int i=0;i<3;i++){ cout<<"i:"<<i<<endl; } //while语句 int j = 3; while(j>0){ cout<<"j:"<<j<<endl; j--; } //do{}while(); int k = 1; do{ k ++; cout<<"k:"<<k<<endl; }while(k<3); //goto是支持的,但是是不推荐使用的。 //bool? if(k){ cout<<k<<"\tis true"<<endl; } //在c++中if(k=0)是没有语法问题的,会给k赋值,而非判断k是否=0所以c++中习惯这么写 //把常量放在前面 //但在java里面会报错 if(0==k){ cout<<"k==0"<<endl; } }