C++学习之if判断for循环while

#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<//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<//for
    for(int i=0;i<3;i++){
        cout<<"i:"<//while语句
    int j = 3;
    while(j>0){
        cout<<"j:"<//do{}while();
    int k = 1;
    do{
        k ++;
        cout<<"k:"<while(k<3);

    //goto是支持的,但是是不推荐使用的。

    //bool?
    if(k){
        cout<"\tis true"<//c++if(k=0)是没有语法问题的,会给k赋值,而非判断k是否=0所以c++中习惯这么写
    //把常量放在前面
    //但在java里面会报错
    if(0==k){
        cout<<"k==0"< 
 

你可能感兴趣的:(C++学习之if判断for循环while)