## Xantox -3

So I would like to know if there's any way to do the following more efficiently:

``while(g[0] = 0 || g[0] = 1 || g[0] = 2 || g[0] = 3 || g[0] = 4 || g[0] = 5 || g[0] = 6 || g[0] = 7 || g[0] = 8 || g[0] = 9)``

I think in other languages (not sure) there's a keyword called in so it would end up something like this:

``while(in.g[0](1, 2, 3, 4, 5, 6, 7, 8, 9))``

Is there anyway to compress all my or's into something more compact?

## jbennet 1,618

Cant you just say while (i< 9 && i > 0)?

## Xantox -3

I only want integers.

## Reprise

http://www.daniweb.com/forums/post1021268.html#post1021268

That post describes how to verify that input is an integer. It takes a user inputted string and looks at each character, one at a time, to make sure it's either an integer (0-9) or the '-' character. Maybe that will help.

## Sky Diploma 571

Firstly, I would like to point out to you that your code is actually assigning values but not comparing them.
[

``while(g[0] = 0 || g[0] = 1 || g[0] = 2 || g[0] = 3 || g[0] = 4 || g[0] = 5 || g[0] = 6 || g[0] = 7 || g[0] = 8 || g[0] = 9)``

This should be ...

``while(g[0] == 0 || g[0] == 1 || g[0] == 2 || g[0] == 3 || g[0] == 4 || g[0] == 5 || g[0] == 6 || g[0] == 7 || g[0] == 8 || g[0] == 9)``

And if you want a better way you can always declare a function,

``````bool check_valid ( int x )
{
for ( int a = 0 ;a < 10; a++ )
if( x == a )
return true ;
return false ;
}``````

And the while loop can be.

``while( check_valid( g[0] ) )``

## Nick Evan 4,005

And if you want a better way you can always declare a function,

``````bool check_valid ( int x )
{
for ( int a = 0 ;a < 10; a++ )
if( x == a )
return true ;
return false ;
}``````

Only problem is that your function has massive overhead. Why not just do:

``````bool check_valid ( int x )
{
if (x >= 0 && x < 10)
return true;
return false;
}``````

or even smaller:

``````bool check_valid ( int x )
{
return (x>=0 && x <10);
}``````

## Sky Diploma 571

Only problem is that your function has massive overhead. Why not just do:

``````bool check_valid ( int x )
{
if (x >= 0 && x < 10)
return true;
return false;
}``````

or even smaller:

``````bool check_valid ( int x )
{
return (x>=0 && x <10);
}``````

I agree that this makes it more efficient . My only approach was to exhibit what the OP was trying to do, with a for loop!!