Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

/t5/acrobat/help-with-calculation/td-p/11887393
Mar 10, 2021
Mar 10, 2021

Copy link to clipboard

Copied

I'm trying to calculate something and I'm having trouble understand calculations.

example:

why is

var s1 = 4;

var x = 1;

for ( var sum = s1; sum<=s1; sum++)x*=sum; result is 20

and why if used like this:

var s1 = 5;

var x = 1;

event.value = x*=sum; result is 5;

whats in "for" that is changing result?

In my case 20 is correct, but why in that case x*=sum is 20 and not 5?

TOPICS

JavaScript

Community Guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Adobe Community Professional
,
Mar 11, 2021
Mar 11, 2021

The way I see it, to get 20 as result is because of for loop for ( var sum = s1(5)-s2(2)+1=4; at this point sum is 4 so x(1)*sum = 4 now in the next loop since sum is now 5, now x(4)*sum(5)= 20. and in the next loop sum is 6 and condition is sum<=s1(5) so there is no more loops so result is 20.

8
Replies
8

/t5/acrobat/help-with-calculation/m-p/11887430#M302231
Mar 10, 2021
Mar 10, 2021

Copy link to clipboard

Copied

What want you calculate?

for ( var sum = s1; sum<=s1; sum++)x*=sum;

is the same as

x *= s1;

Community Guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Marietaa
AUTHOR

Explorer
,

/t5/acrobat/help-with-calculation/m-p/11887445#M302233
Mar 10, 2021
Mar 10, 2021

Copy link to clipboard

Copied

Community Guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

/t5/acrobat/help-with-calculation/m-p/11887459#M302234
Mar 10, 2021
Mar 10, 2021

Copy link to clipboard

Copied

I don't know where does you get the 20.

When I execute this in the Javascript console I get following:

var s1 = 4;

var x = 1;

for ( var sum = s1; sum<=s1; sum++)x*=sum;

x;

4

Community Guidelines

Marietaa
AUTHOR

Explorer
,

/t5/acrobat/help-with-calculation/m-p/11887510#M302239
Mar 11, 2021
Mar 11, 2021

Copy link to clipboard

Copied

Community Guidelines

/t5/acrobat/help-with-calculation/m-p/11887513#M302240
Mar 11, 2021
Mar 11, 2021

Copy link to clipboard

Copied

This is a other for loop!

Try the script of your first posting.

When you use a other script you will get also a other result.

Community Guidelines

Marietaa
AUTHOR

Explorer
,

/t5/acrobat/help-with-calculation/m-p/11887903#M302265
Mar 11, 2021
Mar 11, 2021

Copy link to clipboard

Copied

Thank you Bernd for your help, I want to understand why is result 20.

Community Guidelines

/t5/acrobat/help-with-calculation/m-p/11888124#M302280
Mar 11, 2021
Mar 11, 2021

Copy link to clipboard

Copied

The result of your first script is not 20

Community Guidelines

Adobe Community Professional
,

LATEST
/t5/acrobat/help-with-calculation/m-p/11889041#M302341
Mar 11, 2021
Mar 11, 2021

Copy link to clipboard

Copied

for ( var sum = s1(5)-s2(2)+1=4; at this point sum is 4 so x(1)*sum = 4

now in the next loop since sum is now 5, now x(4)*sum(5)= 20.

and in the next loop sum is 6 and condition is sum<=s1(5) so there is no more loops so result is 20.

Community Guidelines

Resources

About Adobe Acrobat

Adobe Inc

Adobe Inc

Adobe Inc

Adobe Acrobat Feature & Workflow

FAQs

Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2021 Adobe. All rights reserved.