Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2004

Tip: Looking for answers? Try searching our database.

How do I count the test steps in a for loop

Thread view: 
Big Daddy - 27 Sep 2004 02:21 GMT
I need to know how to count the test steps in a for loop for a project.
I think it should work if the count is done in a method that the test is
compared to but can't get it to work.

for( int i =0; i < n || countTest(); i++)

countTest(){
  countCompare++;
  return true;
}

What am I doing wrong?
SMC - 27 Sep 2004 05:08 GMT
> I need to know how to count the test steps in a for loop for a project.
> I think it should work if the count is done in a method that the test is
[quoted text clipped - 8 lines]
>
> What am I doing wrong?

I usually don't like doing other people's homework but... ;-)

Make your || an && and swap the operands (countTest() && i<n). Go see:

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/relational.html

to find out why (hint: "conditionally evaluates op2").

Cheers,
Signature

Sean

Age and treachery will beat youth and skill any day

Oscar kind - 27 Sep 2004 05:30 GMT
> I need to know how to count the test steps in a for loop for a project.
> I think it should work if the count is done in a method that the test is
[quoted text clipped - 8 lines]
>
> What am I doing wrong?

The countTest() method isn't called until i >= n; then it is called each
iteration. The loop loops forever.

What you meant to do is to call the method each time the test "i < n"
succeeds, but not otherwise. You need one of the shortcut operators for
that (that was a good choice of you), but you need the "and" shortcut
operator:

a || b -> Evaluate a; if it is false, evaluate b; return the logical OR
a && b -> Evaluate a; if it is true, evaluate b; return the logical AND

Signature

Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2

Stefan Schulz - 27 Sep 2004 07:23 GMT
> I need to know how to count the test steps in a for loop for a project.
> I think it should work if the count is done in a method that the test is
[quoted text clipped - 8 lines]
>
> What am I doing wrong?

Two things:

1) You are abusing the operator. Why not  move the call to countTest()  
into the
body of the loop?

2) If you insist on abusing an operator, pick the one that works. && in  
this case.

Signature

Whom the gods wish to destroy they first call promising.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.