954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Testing for Conditions in a program

I've used "if and else" statements to test for conditions, but if's can get very "iffy" sometimes. Specially when you need to test for several possibilites.

I was wondering if there is another way to do tests for conditions instead of using the IF. Just for better programming.

example: tic-tac-toe
testing to see if X is three in a row or
O is three in a row.

If anyone knows of a better way to "test" instead of using IF ELSE stuff, I would be happy to hear from ya.

Geek-Master
Junior Poster
158 posts since Dec 2004
Reputation Points: 12
Solved Threads: 7
 

It would probably be easier if you posted a real example of an if tree that you don't like.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

Dave's right we need more context. It sounds like you might be looking for the switch statement.

switch(expression)
{
case constant-expression : statements; break;
.
.
<em>n</em>
default : statements;

}
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
 

I'm just looking for other methods to test input or conditions.

hollystyles, you say that I can look at "switch statements". Then I will do some research on them. Thanks

Geek-Master
Junior Poster
158 posts since Dec 2004
Reputation Points: 12
Solved Threads: 7
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You