Skip to main content
MADink_Designs27
Inspiring
June 16, 2021
Answered

Print For Loop Results using Modulus Operator in Console

  • June 16, 2021
  • 1 reply
  • 2503 views

How do I print the results of var i in a for loop using console.PrintIn();?

I'm writing the for loops to target specific button widgets that are 1 to 9 (this.getField("button." + 1, 3, 5, 7, 9) to hide those specific widgets. I'm trying to figure out why this isn't working by writing a for loop that will return odd numbers using the modulus operator.

I'm getting an error that console.printIn() is not a function. I've tried several variations of the below code...

 

 

for(var i = 1; i < 10; i++) {
	if((i % 2) != 0) {
		console.printIn(i);
	}
}

 

 

Here's the actual code I'm writing. I'm not getting any JS errors, but the addition of this snippet seems to crash Acrobat everytime whereas it did not before the new for loop was introduced:

 

for(var i = 1; i < 10; i++) {
	if(i % 2 != 0) {
		this.getField("enclosure.2." + i).display = display.hidden;
		this.getField("enclosure.4." + i).display = display.hidden;
		this.getField("enclosure.6." + i).display = display.hidden;
	}
}

 

This topic has been closed for replies.
Correct answer try67

It's println, not printIn...

 

PS. An easier way of doing what you're trying to do is to increment the value of i by 2 in each iteration, instead of using the modulo operator...

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 16, 2021

It's println, not printIn...

 

PS. An easier way of doing what you're trying to do is to increment the value of i by 2 in each iteration, instead of using the modulo operator...

MADink_Designs27
Inspiring
June 16, 2021

I knew it was something easy. Thanks for the tip!

Would incrementing what you're suggesting be something like:

 

 

for(var i = 1; i < 10; i+2) {
	console.println(i);
}

 

well that would create an infinite loop, so that wouldn't be correct...

This is more like it. Thanks again!

for(var i = 1; i < 10; i+= 2) {
	console.println(i);
}
try67
Community Expert
Community Expert
June 16, 2021

Correct, the latter is the correct version.