TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Syed Arbab Ahmed
NA
104
0
What are the values of for loop and if statement?
Jun 16 2011 1:47 AM
Hi!
I have written the following program from a book, this program is basically for an exception,
first
I don't understand the follow of this program, specially the values in for loop and in if statement,
secondly
the only output is
this script
and nothing is happening, in
Red
I am writing what I understand and after the program I have few questions:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Exception test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script language="Javascript">
function primeTest(n)
{
document.write ("Testing"+n+":")
try{
if (n<1 || n>20) throw "It's out of range"
//n is less than 1 or greater than 20
for(var i =2; i <n; ++i)
//I is equal to 2 increment in I till I is less than n
if (n% i ==0) throw "It's divisible by"+
//n divide by 0 reminder 0, then "It's divisible by"
document.writeln("It's prime. <br>")
//if 0 then its prime
}
catch(exception){
//otherwise catch
document.writeln(exception+'<br>')
//Write exception
}
}
</script>
<meta content="MSHTML 6.00.2900.6082" name="GENERATOR"></head>
<body>
<p>this script </p>
<script language="javascript">
<!-
for(i=0;i<=21;++i)
//this is comment
{
primeTest(i)
}
-></script>
</body></html>
Questions:
1-At 1
st
what is the value of n? Since we have not declared it?
2-The 1
st
value of I is 2?
Thanks in advance
Reply
Answers (
2
)
Software Testers
Example for regression testing