making more than one test in a 'for' statement ?

T

ThaDoctor

Hi....


I would just like to know about whether I can make more than one test
in one for statement...
As I would like to know this in relation to a project I am working on
(simple-the-game.sf.net I think)
there is no webpage but that is my project page.
There is no code either but that is mainly becourse I haven't got
anything up by now.... It is a game, or it is something that should
turn out as a console game (text based).

Greetings from Denmark.
 
V

Victor Bazarov

ThaDoctor said:
I would just like to know about whether I can make more than one test
in one for statement...

The second part of a 'for' statement is a logical expression, you can
put any expression you wish in there. Use &&, ||, ==, !=, to combine
logical subexpressions.
As I would like to know this in relation to a project [...]

That's irrelevant.

V
 
G

Guest

Hi....


I would just like to know about whether I can make more than one test
in one for statement...
As I would like to know this in relation to a project I am working on
(simple-the-game.sf.net I think)
there is no webpage but that is my project page.
There is no code either but that is mainly becourse I haven't got
anything up by now.... It is a game, or it is something that should
turn out as a console game (text based).

Use the logical operators && or || to separate the test, so if you want
to check if both a and b are greater than 0 then you write

if (a > 0 && b > 0)

If you only need one of them to be greater then 0 use || instead.
 
J

Jim Langston

ThaDoctor said:
Hi....


I would just like to know about whether I can make more than one test
in one for statement...
As I would like to know this in relation to a project I am working on
(simple-the-game.sf.net I think)
there is no webpage but that is my project page.
There is no code either but that is mainly becourse I haven't got
anything up by now.... It is a game, or it is something that should
turn out as a console game (text based).

Like Victor and Erik said, you need to use boolean and and or.

int count = 0;
for ( int i = 0; i < 100 && count < 5; ++i )

Which would continue until either i is greater than 100 or count is greater
than 5.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top