Hi All,

Small can some please let me know hpw to use logical OR in csh scripts, below is the code line which is not running and i don't know why it is entring in "if" statement, even though i'm inputing value "1",

set ans = $<
echo $ans
if ( $ans != 1 || $ans != "2" ) then
echo "Invalid option selected. Exixting from the from the script $0 ."
exit 0
endif

It goes in if clause and then exits from the script
Any suggestions pls .???

Because 1 != 2. If you want it to enter the if statement only when the input is not 1 and not 2, then you need to use the logical and (&&), not the logical (or).

If you wanted to enter the loop only if the answer is either 1 or 2, then you would use the logical or. i.e.

if ( $ans == 1 || $ans == 2 ) then

but, when you invert the == to !=, then you must also invert the or to an and, because every number is either not equal to one or not equal to two, one and two included.

Because 1 != 2. If you want it to enter the if statement only when the input is not 1 and not 2, then you need to use the logical and (&&), not the logical (or).

If you wanted to enter the loop only if the answer is either 1 or 2, then you would use the logical or. i.e.

if ( $ans == 1 || $ans == 2 ) then

but, when you invert the == to !=, then you must also invert the or to an and, because every number is either not equal to one or not equal to two, one and two included.

Thanks mate Its working now !!!
It's an logical error from part .. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.