0

嗨,对于这样一个愚蠢的问题,我很抱歉,我正在根据分段控件的索引更改变量值,但随后想在随后的计算中使用该变量;确定这与变量范围有关吗?

- (IBAction)calculate:(UIButton *)button {
if( [sSeg selectedSegmentIndex]==1){
    float  s=0.5;
    NSLog(@"s=%f", s);
}
else if ([sSeg selectedSegmentIndex]==0)
{
    float s=1; 
    NSLog(@"s=%f", s);
}
NSLog(@”s now = %f”, s);

}

非常感谢帮助!

4

2 回答 2

4
- (IBAction)calculate:(UIButton *)button {
    float s = 0;
    if( [sSeg selectedSegmentIndex]==1){
        s=0.5;
        NSLog(@"s=%f", s);
    }
    else if ([sSeg selectedSegmentIndex]==0)
    {
        s=1; 
        NSLog(@"s=%f", s);
    }
    NSLog(@”s now = %f”, s);

}

是的,它的范围 - 一个变量只在你的大括号内可见。

于 2010-12-09T01:37:31.363 回答
0
- (IBAction)calculate:(UIButton *)button {
    float s;
    if( [sSeg selectedSegmentIndex]==1){
        s=0.5;
        NSLog(@"s=%f", s);
    }
    else if ([sSeg selectedSegmentIndex]==0)
    {
        s=1; 
        NSLog(@"s=%f", s);
    }
    NSLog(@”s now = %f”, s);
}
于 2010-12-09T01:35:34.867 回答