AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

newbie help loop

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
abskiz
Guest





PostPosted: Fri Dec 12, 2003 7:17 pm    Post subject: newbie help loop Reply with quote



how do u find out how many times a loop executes?

like

for (int i=8; i<12; i++);

that will execute 12-8+1 tiems right?



Back to top
Wendy S
Guest





PostPosted: Fri Dec 12, 2003 7:53 pm    Post subject: Re: newbie help loop Reply with quote



"abskiz" <someone (AT) microsoft (DOT) com> wrote

Quote:
how do u find out how many times a loop executes?
for (int i=8; i<12; i++);
that will execute 12-8+1 tiems right?

Probably the easiest way is to put a print statement inside the loop, and
execute it:

for (int i=8; i<12; i++) {
System.out.println( "i = " + i );
}

The question isn't very clear. Do you want to know how many times the
condition will be evaluated? Or how many times the code in the body of the
loop will be executed?

--
Wendy



Back to top
abskiz
Guest





PostPosted: Sat Dec 13, 2003 3:18 am    Post subject: Re: newbie help loop Reply with quote



how many times the code in the body of the loop will executes
"Wendy S" <wendywds (AT) hotmail (DOT) com> wrote

Quote:
"abskiz" <someone (AT) microsoft (DOT) com> wrote in message
news:KtoCb.14339$aF2.1601848 (AT) news20 (DOT) bellglobal.com...
how do u find out how many times a loop executes?
for (int i=8; i<12; i++);
that will execute 12-8+1 tiems right?

Probably the easiest way is to put a print statement inside the loop, and
execute it:

for (int i=8; i<12; i++) {
System.out.println( "i = " + i );
}

The question isn't very clear. Do you want to know how many times the
condition will be evaluated? Or how many times the code in the body of
the
loop will be executed?

--
Wendy





Back to top
Brad BARCLAY
Guest





PostPosted: Sat Dec 13, 2003 3:49 am    Post subject: Re: newbie help loop Reply with quote

abskiz wrote:
Quote:
how do u find out how many times a loop executes?

like

for (int i=8; i<12; i++);

that will execute 12-8+1 tiems right?

No, the above example will only iterate 12-8 times. If you want it to
iterate 12-8+1 times, you need to be inclusive of the end range, such as:

for (int i=8;i<=12;i++);

HTH!

Brad BARCLAY

--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project: http://www.jsyncmanager.org


Back to top
Anthony Borla
Guest





PostPosted: Sat Dec 13, 2003 4:01 am    Post subject: Re: newbie help loop Reply with quote

"abskiz" <someone (AT) microsoft (DOT) com> wrote


Quote:

Probably the easiest way is to put a print statement
inside the loop, and execute it:

for (int i=8; i<12; i++) {
System.out.println( "i = " + i );
}

The question isn't very clear. Do you want to know how
many times the condition will be evaluated? Or how many
times the code in the body of the loop will be executed?



how many times the code in the body of the loop
will executes


So just place a 'print' statement in the loop body, as Wendy illustrated, or
use a counter variable:

int loopCount = 0;

for (...)
{
...
++loopCount;
...
}

System.out.println("Loop executed " + loopCount + " times");

I hope this helps.

Anthony Borla



Back to top
Tor Iver Wilhelmsen
Guest





PostPosted: Sat Dec 13, 2003 8:23 am    Post subject: Re: newbie help loop Reply with quote

"abskiz" <someone (AT) microsoft (DOT) com> writes:

Quote:
how do u find out how many times a loop executes?

By counting.

int count = 0;
for (int i=8; i<12; i++) count++;
System.out.println("Executed "+count+" times");

Back to top
Paul Thompson
Guest





PostPosted: Sun Dec 28, 2003 8:43 pm    Post subject: Re: newbie help loop Reply with quote

Tor Iver Wilhelmsen wrote:
Quote:
"abskiz" <someone (AT) microsoft (DOT) com> writes:


how do u find out how many times a loop executes?


By counting.

int count = 0;
for (int i=8; i<12; i++) count++;
System.out.println("Executed "+count+" times");

int i;
for (i=8; i<12; i++) loop;
print (i-Cool;


Back to top
Tor Iver Wilhelmsen
Guest





PostPosted: Mon Dec 29, 2003 10:23 am    Post subject: Re: newbie help loop Reply with quote

Paul Thompson <pault (AT) HiWAAY (DOT) net> writes:

Quote:
for (i=8; i<12; i++) loop;
print (i-Cool;

Only works when the incrementor is +1, if you used a loop with i+= 2
or i-- that would not work, while mine would. :)

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.