0
;(function () {
    var n = readline(), r = 0;
    for (var i = 0; i < n; i++) 
        r += readline().split(' ').filter(function(v){ return v == 1;}).length > 1;
    print(r);        
}).call(this);

Why we add ; before the function and why we don't put {} for the for loop?.

LostMyGlasses
  • 3,074
  • 20
  • 28
Abdel-Raouf
  • 700
  • 1
  • 8
  • 20
  • 2
    `;` just to make the script fail-safe if it is concatenated with other scripts. `{}` they are optional as there is only one line to be executed in the `for` loop – Andreas Sep 06 '15 at 16:01
  • ok that's good for the function but in for loop as you said {} are optional when i try to put the {} ,for loop crash the whole function, could you explain that ? @Andreas – Abdel-Raouf Sep 06 '15 at 16:08
  • When not inside an expression or part of a function definition, `{expr1; expr2; exprN;}` is a code block. You can use them almost anywhere, they're just less useful in _JavaScript_ which doesn't give them `var` scope (though they do get `let` scope). This means you often only see them used with `if`, `for`, `while`, etc. Using them lets you group together many `;` delimited expressions and statements. – Paul S. Sep 06 '15 at 16:08
  • Read the docs on MDN about statement after the for loop https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for – epascarello Sep 06 '15 at 16:08

1 Answers1

0

The parenthesis in the for loop are omitted because it's only one line of code, in that case you do not need them. The ; is a fail-safe if you include this in other scripts.

  • but i know that you could put them or not ,as you want ,as it is one code line so when i try to put them it doesn't work and crash all the function , could you explain me this ? – Abdel-Raouf Sep 06 '15 at 16:02