Dart - 用于循环不循环

时间:2016-05-07 12:03:25

标签: dart

for(n = 0; n < length - 1; n++);
{   
    if(sbin[n] == '1'){
        ctr = ctr + 1;
        print(sbin[0]);
    }
}
return ('Bit counter - $ctr');

它只显示了sbin的第一个字母。

1 个答案:

答案 0 :(得分:1)

main() {
  print(someFunction());
}
  someFunction() {
  var length = 5;
  var sbin = ['1', '2', '3', '4', '5'];
  var ctr = 0;

  for(var n = 0; n < length - 1; n++) {   
      if(sbin[n] == '1'){
          ctr = ctr + 1;
          print(sbin[0]);
      }
  }
    return ('Bit counter - $ctr');
}

DartPad example