## mark192

I've been programming for about a week now and I'm just learning if statements now

I made a simple program that asks the user for a number input (1-4) and depending on what they input it will add/subtract/multiply/divide 2 numbers they enter after they decide what operation they want to perform.

I made an if statement that says if the number is not equal to 1, 2, 3, 4, then it gives an error message and then asks them to re enter their choice (1-4)

However I'm not sure how to redirect the program back to the start of the code after this this way it doesn't just end after the number is re-entered.

I appreciate any help, thanks keep in mind I'm a noob at this :D

## mark192

also say i wanted to list several numbers in one if statement how would i do that?

``If (x != 1, 2, 3, 4)``

Doesn't seem to be working

## Colin Mac 53

Some if else statements would be better

also say i wanted to list several numbers in one if statement how would i do that?

## VernonDozier 2,218

also say i wanted to list several numbers in one if statement how would i do that?

``If (x != 1, 2, 3, 4)``

Doesn't seem to be working

&& means "and". || means "or".

Try this:

``if (x != 1 && x != 2 && x != 3 && x != 4)``

or this:

``if (!(x == 1 || x == 2 || x == 3 || x == 4))``

## Ancient Dragon 5,243

or try this `if( x > 0 && x < 5)`

## invisal 381

For your redirecting question, you could use `do...while` loop:

``````do {
} while (x < 1 && x > 5); // If the input isn't in the range of 1-4, it will process the code in the loop block again.``````
commented: good alternate solution +23

## Ancient Dragon 5,243

Invisal: line 3: x can not be both at the same time. It should have use the || operator, not && :)

commented: Thanks for point out +3

## invisal 381

Invisal: line 3: x can not be both at the same time. It should have use the || operator, not && :)