我想替换一个
#define INTERVAL_MASK(b) (1 << (b))
Run Code Online (Sandbox Code Playgroud)
具有内联函数.
int INTERVAL_MASK(int b)
{
return (1 << b);
}
Run Code Online (Sandbox Code Playgroud)
但我有一个switch case,它在case语句中使用预处理器指令.怎么去转换呢?更换switch搭配if是唯一的选择吗?
如何在XSD中进行/或验证?例如,在下面的xml片段中,如果action是A(add),则后续属性和元素是required:
<Post postID="22793" action="A" ...>
<Transaction ...>
<Disposition ...>
<AccountInformation ... />
<ThirdPartyInformation ... />
</Disposition>
<IndividualInformation ... />
</Transaction>
...
</Post>
Run Code Online (Sandbox Code Playgroud)
但是如果动作是D则禁止后续属性和属性::
<Post postID="22793" action="D" />
Run Code Online (Sandbox Code Playgroud)
即:如果操作是delete(D),则其余属性将从中更改
至
并且后续元素从中切换
minOccurences="1" maxOccurrences="unbounded"
Run Code Online (Sandbox Code Playgroud)
至
minOccurrences="0" maxOccurrences="0"
Run Code Online (Sandbox Code Playgroud)
是否可以使用XSD来定义xml结构?
这是示例代码.
<?php
$a =2;
switch($a) {
case 1:
case 2:
case 3:
echo "Logic for error validations";
case 1:
echo "1. code to be executed";
break;
case 2:
echo "2. code to be executed";
break;
case 3:
echo "3. code to be executed";
break;
case 4:
echo "4. code to be executed";
break;
case 5:
echo "5. code to be executed";
break;
}
?>
Run Code Online (Sandbox Code Playgroud)
对于$aas 的值,1,2,3我有相同的错误验证.对于$ a的每个值,更新逻辑再次不同.
为了实现上述逻辑,我使用了案例1:案例2:案例3:并没有故意使用BREAK.这样它就会继续执行.
但它导致o/p, 错误验证的逻辑1.要执行的代码.
现在预期的输出是,错误验证的逻辑2.要执行的代码.
请帮助我或建议更改以产生预期的输出.我可以使用IF并基于$ a的值,更改代码.但我正在尝试使用switch的帮助,可以扩展为$ …
嗨,我正在调用ALAssetsLibrary
-enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:block failureBlock:failure;
Run Code Online (Sandbox Code Playgroud)
然后在枚举块内我想比较返回的组的类型并将其添加到相关的数组.我试过了
^( ALAssetsGroup *group, BOOL *stop )
{
NSLog(@"Group %@", group );
ALAssetGroupType assetType = (ALAssetGroupType)[group valueForProperty:ALAssetsGroupPropertyType];
NSLog( @"Asset type %@", assetType );
switch( assetType )
{
case ALAssetsGroupAplbum :
NSLog( @"Found ALBUM" );
[albums addObject:group];
break;
}
}
Run Code Online (Sandbox Code Playgroud)
初始日志记录出"组ALAssetsGroup - 名称:照片库,类型:专辑,资产数量:177"
下一个日志是"资产类型2"
但第三个日志永远不会被调用.
我有什么想法吗?
iphone switch-statement constant-expression objective-c-blocks
#include <iostream>
using namespace std;
int main(){
char i;
cin >>i;
switch (i){
case ('e'||'i'||'o'||'u'||'a'):
cout<<"Vowel";
break;
case ('+'||'-'||'/'||'*'||'%'):
cout<<"Op";
break;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果不是我们如何在交换机中使用比较或逻辑运算符?为什么我们不能在不使用范围的情况下在单个案例中声明和初始化变量?
好的,我现在有一个目标是进行基本的文本冒险.但是,要做到这一点,我需要/想要一个可以执行以下操作的switch语句:
我怎么做到这一点?你能告诉我这个具体例子的编码吗:
提示用户输入数据.switch语句将"look box"视为一种情况,并将"sleep"视为另一种情况.程序不关心任何单词的顺序,但是关心字母的顺序.
请详细解释一切.我刚刚开始编码.
编辑:谢谢你的所有答案.我知道有更好,更复杂,更有用的处理方法,但它还不是我的水平.
好吧,我有这个麻烦,我一直在处理,但我不能让它工作
我有这个功能
function getDirections(dir)
{
var img;
switch(dir)
{
case 0:
img+='N.png';
break;
case 1:
img+='NE.png';
break;
case 2:
img+='E.png';
break;
case 3:
img+='SE.png';
break;
case 4:
img+='S.png';
break;
case 5:
img+='SO.png';
break;
case 6:
img+='O.png';
break;
case 7:
img+='NO.png';
break;
default:
alert('enetered default but direction='+dir);
}
return img;
}
Run Code Online (Sandbox Code Playgroud)
很简单吧?现在我将此间隔设置为5000毫秒来调用getDirections(变量),该函数在第一次调用时工作良好但在此之后,它总是输入default子句并且它还会警告'输入默认值但方向= dirvalue',我的意思是即使dir是一个介于0-7之间的值,它总是会进入默认值:但是它会提醒值,所以它被用来输入其中一个案例.
我使用其他如果和它工作所以相同,所以我不知道SWITCH有什么问题
if(dir==0){img+='N.png';}
else if(dir==1){img+='NE.png';}
else if(dir==2){img+='E.png';}
else if(dir==3){img+='SE.png';}
else if(dir==4){img+='S.png';}
else if(dir==5){img+='SO.png';}
else if(dir==6){img+='O.png';}
else if(dir==7){img+='NO.png';}
Run Code Online (Sandbox Code Playgroud) 如果注释nslog-line,则会出错:
语义问题:使用未声明的标识符'alert'
switch ([[array objectAtIndex:0]intValue]) {
case 2:
NSLog(@"Allergie alarm"); << commenting this, gives me an error!!!
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"blabal"
message: @"balbalb"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
[alert release];
break;
default:
break;
}
Run Code Online (Sandbox Code Playgroud) 如果我这样做会更好:
if(message == 'redirect')
{
is_valid.accepted = true;
}
else if(message == 'invalid id')
{
is_valid.accepted = false;
}
else
{
is_valid.accepted = false;
}
Run Code Online (Sandbox Code Playgroud)
或者我是这样做的
switch (message)
{
case 'invalid id':
default:
is_valid.accepted = false;
break;
case 'redirect':
is_valid.accepted = true;
break;
}
Run Code Online (Sandbox Code Playgroud) 我在我的一个文件中有这段代码:
switch ([sender tag]){
...
case 100:
UIView *v1 = [UIView alloc] initWithFrame blabllabla...
[v1 bla bla bla...
break;
...
Run Code Online (Sandbox Code Playgroud)
看起来很标准吧?但它给了我这个错误:
"Use of undeclared v1"
Run Code Online (Sandbox Code Playgroud)
然后我放了一个"NSLog()"或"if"语句,如下所示:
case 100:
NSLog(@"why need a nslog here?");
Run Code Online (Sandbox Code Playgroud)
要么
case 100:
if(1==1) {
...
Run Code Online (Sandbox Code Playgroud)
然后它工作.
谁知道为什么会这样?这是我的代码还是客观规则?
switch-statement ×10
c++ ×2
iphone ×2
javascript ×2
objective-c ×2
adventure ×1
c ×1
c# ×1
if-statement ×1
php ×1
string ×1
text-based ×1
xml ×1
xsd ×1