if语句中obj-c预期表达式错误

时间:2016-12-27 01:43:50

标签: objective-c xcode8

使用obj-c编码新手的一个简单问题... 看看这段代码:

**int main(int argc, const char * argv[]) {
@autoreleasepool {
    // insert code here...
    //NSLog(@"Hello, World!");

    int a,b;

    a = 5;
    b = 6;
    if (a ==b) NSLog(@ "a is equal to b");
    if (a !=b)  NSLog(@ " a is not equal to b" );
    if (a > b)  NSLog(@ " a is greater that b");
    if ( a < b)  NSLog(@ " a is less than b");
    if ( a >= b)  NSLog(@ " a is greater of equal to b");
    if (a <= b) NSLog(@ " a is less or equal to b");
    if (!(a == b)) NSLog(@ " a is not (Equal to b)");
    if ((a == b)  || ( a =-- b )) NSLog(@ " a is equal to be, or a is equal to -- b");
    if ((a <= b) && (a < ++b)) NSLog(@ " a is less than or equal to b, and a is less than ++b");
    if (a == b) NSLog(@" a is equal to b");

    if ( a == b); {

        NSLog(@" a is equal to b");
    }

    else  NSLog (@ " a is not equal to b");

    BOOL z = ( a == b);
    if (!z) NSLog(@ " a is not (equal to b)");
    BOOL y = ( a > b);
    if ( y != YES) NSLog(@ " a is NOT ( greater than b");
    return 0;
    }
}**

我在else语句中得到了错误,表达了预期的表达。 我在这做错了什么?我错过了什么? 使用xcode版本8.2.1

1 个答案:

答案 0 :(得分:0)

问题代码在这里:

$(function(){

     $('.sample').on('show.bs.modal', function () {
       alert($(this).attr('id'));
    });
});

第一行相当于

if ( a == b); {

    NSLog(@" a is equal to b");
}

else  NSLog (@ " a is not equal to b");

因为分号(if ( a == b) {} { )是一个空语句。这会将;转换为单语句条件。后面的左括号不再是if ()语句的一部分,而是开始一个新的独立块。

这使得后面的if ()不属于else { ... }语句,因此无效。