Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How do I count the test steps in a for loop
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?

Report this thread to moderator Post Follow-up to this message
Old Post
Big Daddy
09-27-04 08:57 AM


Re: How do I count the test steps in a for loop
On Mon, 27 Sep 2004 11:21:08 +1000, Big Daddy wrote:

> 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?

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/tuto...relational.html

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

Cheers,
--
Sean

Age and treachery will beat youth and skill any day

Report this thread to moderator Post Follow-up to this message
Old Post
SMC
09-27-04 08:57 AM


Re: How do I count the test steps in a for loop
Big Daddy <bigdoglinux@yahoo.comm> wrote:
> 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?

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


--
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

Report this thread to moderator Post Follow-up to this message
Old Post
Oscar kind
09-27-04 08:57 AM


Re: How do I count the test steps in a for loop
On Mon, 27 Sep 2004 01:21:08 GMT, Big Daddy <bigdoglinux@yahoo.comm> wrote:

> 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?

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.


--

Whom the gods wish to destroy they first call promising.

Report this thread to moderator Post Follow-up to this message
Old Post
Stefan Schulz
09-27-04 08:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:30 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.