View Full Version : variable valuation in the for statement

11-11-2012, 02:29 AM
Hi folks.

I know numbertohide = 2.

How come

for (var h=numbertohide;h<6;h++)

inputselectionelementid = '#inputselection' + h;
console.log('hide ' + inputselectionelementid);
does not work? Only var h=2 directly properly executes the loop.


11-11-2012, 03:46 AM
not sure why, bt they way you've formed your code, I can tell you theres probably an easier way to do what you are doing, since you are apparently using jQuery.

Would you mind showing some more, maybe we can help you reach your overall goal a little better?

- loop looks fine to me, most likely answer is that numbertohide isnt coming to 2, like you think it is

11-11-2012, 02:35 PM
Yup it was my mistake, numbertohide wasn't actually coming out to 2.

Thanks Dan