Today, the editor will share the if-else branch statement of C++
1. if single branch statement
![](https://img-blog.csdnimg.cn/img_convert/56aac7e62b5d142cb46aceb48d819893.png)
Format:
if (judgment statement)
{
execute statement;
}
For example:
if (a == b){
cout<<"hello";
}
If a=b, output "hello"
2. if-else double branch statement
![](https://img-blog.csdnimg.cn/img_convert/fba899701fdc8ede7c7d4bdc454ea95b.png)
Format:
if (judgment statement)
{
execute statement;
}
else
{
execute statement;
}
For example:
if (a == b){
cout<<"hello";
}
else{
cout<<"hi";
}
If a=b, output "hello", otherwise output "hi"
2. if-else multi-branch statement
![](https://img-blog.csdnimg.cn/img_convert/bea76ae6dc6a3c27d4e51adb3293a147.png)
Format:
if (judgment statement 1)
{
Execute statement 1;
}
else if (judgment statement 2)
{
Execute statement 2;
}
……
else
{
Execute statement m;
}
For example:
if (a == b){
cout<<"hello";
}
else if (a == c){
cout<<"bye";
}
else if (a == d){
cout<<"good morning";
}
else{
cout<<"hi";
}
If a=b, output "hello", if a=c, output "bye", if a = d, output "good morning", otherwise output "hi"
The above is the knowledge sharing~
Remember to like it!