while(1)
{
if(a)
break;
if(b)
break;
if(c)
{
cout<<"hello";
}
break;
}
上述程序实现了逻辑与功能
if(!a && !b && c)
cout <<"hello";
总结: 使用while循环1次的方式,实现了逻辑与的功能
优势在于,针对每一种情况都还可以输出,如下所示,对于仅有a成立的情况还可以进行操作。
倘若仅用if中的与操作,则需要再单独写代码,不如这个形式简单。
while(1)
{
if(a)
{
cout <<"this a";
break;
}
if(b)
{
cout <<"this b";
break;
}
if(c)
{
cout<<"hello";
}
break;
}