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.