# Thread: is it possible to double a command without a loop?

1. ## is it possible to double a command without a loop?

if I have an int with a value and I want to make a command repeat itself that values times?

and is there a command regarding even and uneven numbers?

and does anybody know if it's possible to redefine an expression?
e.g
if at the beginning of my code i defined abc as +
can I redefine it to - at another point in my code?

2. Originally Posted by NA84
if I have an int with a value and I want to make a command repeat itself that values times?
goto if you must tho' it is best avoided.
Originally Posted by NA84
and is there a command regarding even and uneven numbers?
Perhaps you mean the modulo operator.
Originally Posted by NA84
and does anybody know if it's possible to redefine an expression?
e.g
if at the beginning of my code i defined abc as +
can I redefine it to - at another point in my code?
First define, then undefine, then re-define.

3. Originally Posted by itCbitC
goto if you must tho' it is best avoided.
Maybe for that particular purpose, but there are good uses of goto.

4. Originally Posted by NA84
if I have an int with a value and I want to make a command repeat itself that values times?
Believe me, you're far better to use a loop than anything else.
Goto will work, but it's generally frowned upon and a real pain to debug.

and is there a command regarding even and uneven numbers?
If you are using integer values, test bit 0... 1 is odd, 0 is even.
Code:
```// true if odd
bool IsOdd(int Value)
{ return Value & 1; }```
and does anybody know if it's possible to redefine an expression?
e.g
if at the beginning of my code i defined abc as +
can I redefine it to - at another point in my code?
If you are just looking to change the sign of the variable you can use x = 0-x; to flip between a positive number and a negative one.

If you mean to flip an equation from adding to subtracting... that's self modifying code which, even amongst bad ideas, is a really bad idea. It would make more sense to use some conditional term to decide whether to add or subtract.

5. Originally Posted by NA84
if I have an int with a value and I want to make a command repeat itself that values times?
A recursive function? Something like this:

Code:
```#include <stdio.h>

void hello( int i )
{
if ( i != 0 )
{
hello( i - 1 );
}

puts( "Hello\n" );
}

int main()
{
hello( 5 );
return 0;
}```

6. thank you all.
one more question...
if i have a counter and I need to printf one thing when the counter is a prime number and a different thing if it's not a prime no'. Do you have a good idea for that??

7. Originally Posted by NA84
thank you all.
one more question...
if i have a counter and I need to printf one thing when the counter is a prime number and a different thing if it's not a prime no'. Do you have a good idea for that??
Obviously you need some algorythm to decide if a number is prime or not.

I'm thinking you need to try writing this program yourself, then if you run into trouble you can post your code here and we'll take a look at it for you.