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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.