else的使用
上一篇我们一起学了if的使用
这次……else登场!
它指的是其他的
所以一定和if配套使用
效果更佳~
来看看示例~
#include<iostream>
using namespace std;
int main(){
if(5%5==0){
cout<<"hehe";
}
else{
cout<<"haha";}
return 0;
注意else后是没有()的
else_if怎么用
它是else的翻版
elseif是否则如果的意思
所以……
一起就是if-elseif-else(一个事情的多个结果)
记得打小括号()里面放条件
来看看示例~
#include<iostream>
using namespace std;
int main(){
if(5%5==0){
cout<<"hehe";
}
else if(102%3==0){
cout<<"haha";}
else{
cout<<"xixi";
return 0;
}
if-else if-else嵌套
其实也就是三个+的else-if+condition+结果
没啥好看的
上面elseif的就是了