Use <= and >= condition in switch and update dataTable Row

I have above datatable.
Now if
Number is >=75 and Number<=100, Grade will A
else
Number is >=60 and Number<=74, Grade will B
else
Number is >=45 and Number<=59, Grade will C
else
Number is >=30 and Number<=44, Grade will D
Number is >=0 and Number<=29, Grade will E

I don’t want to use if-else, instead, can I use switch, also as per number i need to update the grade in DataTable.
Any help will be highly appreciated.

Any experts please look into this?

Here, No need of Switch Activity to update the Grade details in the DataTable. You can Write all conditions in assign activity with if Condition as Below.

Solution : UiPathForum_157104.zip (12.8 KB)

In for Each of row of DataTable

Num = Cint(row(“Number”))

row(“Grade”) = If (Num >=75 And Num <= 100 , “A”, _
If (Num >=60 And Num <= 74 , “B”, _
If (Num >=45 And Num <= 59 , “C”, _
If (Num >=30 And Num <= 44 , “D”, _
If (Num >=0 And Num <= 29 , “E”,“Not Applicable”)))))

Thanks.!

Thanks a lot for looking into this.
One doubt i have, in below code:
If (Num >=75 And Num <= 100 , “A”, _
Why we have used _( Under Score) after “A” . As i tried code without _ and it works fine. Please manage sometime to look into this.

1 Like

Underscore is To break a single statement into multiple lines. If you write entire statement in one single line without underscore also it will work. But, When you are writing lengthy statements prefer to use underscore to break the statement into multiple lines.

Thanks.!