var _tmp = 0;
for (var i = 0; sys.cores()[i]["sn"] != null; i++) { _tmp++; alert(_tmp); }
alert ("Pretty sure, you have " + _tmp + " virtual cores.");

This is the code that I'm working on. The loop itself is very simple. The output is: 1, 2, 3, 4. Just like expected, 4 virtual cores. But the alert() after it, is not executed. Reason behind it is that:

os.cpus()[0]["model"] // TRUE, _tmp = 1;
os.cpus()[1]["model"] // TRUE, _tmp = 2;
os.cpus()[2]["model"] // TRUE, _tmp = 3;
os.cpus()[3]["model"] // TRUE, _tmp = 4;
os.cpus()[4]["model"] // FALSE/NULL -> ERROR -> HALT!

So interpreter skips further code execution. I'd still like to know ways to solve that kind of issue.

The error:

Uncaught TypeError: Cannot read property 'model' of undefined.

Edited by happygeek: moved

2 Years
Discussion Span
Last Post by Aeonix

I have solution on my personal problem.

var i = 0;
var _tmp;
var cpuCores;

_tmp = sys.cores().length;
cpuCores = _tmp;

alert ("Pretty sure, you have " + cpuCores + " virtual cores.");

But I can't escape forever. The request on answer on how to perform this with for() or while() still remains.

Edited by Aeonix

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.