选择结构

选择结构

if单选择结构

if(布尔表达式){
    //如果布尔表达式为true将执行的语句
}

if双选择结构

if(布尔表达式){
    //如果布尔表达式为true
}else{
    //如果布尔表达式为false
}

if多选择结构

if(布尔表达式1){
    //如果布尔表达式1为true所执行的代码
}else if(布尔表达式2){
    //如果布尔表达式2为true所执行的代码
}else if(布尔表达式3){
    //如果布尔表达式3为true所执行的代码
}else{
    //如果布尔表达式都不为true所执行的代码
}

嵌套的if结构

if(布尔表达式1){
    //如果布尔表达式1为true所执行的代码
    if(布尔表达式2){
        //如果布尔表达式为true所执行的代码
    }
}

switch多选择结构

switch(expression){
    case value :
        //语句
        break;//可选
    case value :
        //语句
        break;//可选
      //你可以选择任意数量的case语句
    default ://可选
        //语句
}

posted @ 2025-02-25 14:58  理性123  阅读(18)  评论(0)    收藏  举报