/    Sign up×
Community /Pin to ProfileBookmark

nested for loop question

for (var jsNot=0;jsNot<10;jsNot++)
{
document.write(“JavaScript is not Java!<br>”);

for (jsNot2=1;jsNot2<2;jsNot2++)

{
document.write(“Are you getting this?<br>”);
}
}

why does the jsNot2 variable in the nested loop automatically get reset to 1 ?

would appreciate it if somebody would be able to explain this to me,

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Nov 10.2006 — because it is being set to 1

for ([B]jsNot2=1[/B];jsNot2<2;jsNot2++)
Copy linkTweet thisAlerts:
@aguntherNov 10.2006 — Since jsNot2 is inside the first loop, it is reset. If you want it to increment globally, place jsNot2=1 before the first loop and jsNot2++ inside the second loop. You will need a different incrementer such as (i=1;i<2;i++) for the second loop.

Al

Registered user wrote:

for (var jsNot=0;jsNot<10;jsNot++)

{

document.write("JavaScript is not Java!<br>");

for (jsNot2=1;jsNot2<2;jsNot2++)

{

document.write("Are you getting this?<br>");

}

}

why does the jsNot2 variable in the nested loop automatically get reset to 1 ?

would appreciate it if somebody would be able to explain this to me,
×

Success!

Help @changintimes spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...