How to use the logical operator "!"?


#1

Hi,

I want to do a while loop with a string.

The loop turns while the string IS NOT equal to a string I specify.

I try to use the ! operator but it doesn’t works.

Witch are the negation operator in UiPath?

Thanks


#2

Hi @nSangui,

Since UIPath is based on VB .NET to develop artifacts, in this case the correct operator is Not.

For example:


#3

Hi,

“!” is a C operator, you need VB.Net (which btw is “Not”).
You can check VB.Net operators here:
https://www.tutorialspoint.com/vb.net/vb.net_operators.htm

Regards,
Andrzej


#4

You can use <> for not equal.
example: value <> 1


#5

Sidenote; I tend to avoid using Not when there is more than one condition as it gets confusing. For example if you had

If
Not isMale or age > 21

Would that be interpreted as not Male and not over 21 or not Male and could be any age? Without testing I’m not sure hence why I would avoid using Not.


#6

So what do you use instead of not?


#7

Try to make the operation a positive one, so rather than saying

not age > 21

say

age <= 21

to avoid the confusion. Not always possible, if it gets too confusing just use one nested if (but no more than one!! :slight_smile: )