cancel
Showing results for
Did you mean:
cancel
Announcements

151
Views
5
4
Replies
Highlighted
Beginner

## IF Statement / Switch Statement / IF, Else, Then

Hello,

I am working on a script that captures expected wait times.  It seems like the best way to handle this is to capture this data into an integer via get reporting statistic > expected wait time.  The problem I am having is what to do with this value after.  I know I can do an if then statement however, what seems like an even better option is the switch statement.  I can't figure out how to use an evaluation within the switch statement.  Would someone please let me know the best way to do this?

For example, I wanted to do something like this

```if (expected wait time is < 0) play prompt 1
if (expected wait time is > 0 and < 60) play prompt 2
if (expected wait time is > 60 and < 300) play prompt 3
if (expected wait time is > 300) play prompt 4```

Currently I only see a way to evaluate one option using the If step and when looking at the switch step I don't see a way to evaluate based on greater than or less than.  It appears the switch step will only allow me to match a condition exactly.

Everyone's tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Beginner

## Re: IF Statement / Switch Statement / IF, Else, Then

I don't think there is anything wrong with using nested IF statements.  There are fewer evaluation steps here than you think.  Only three, not four.

There isn't anything wrong with adding logic and another step item--Switch step.  It only counts against your total step count.

If all you are doing is playing a single prompt, save yourself a few steps.  ...just make sure you account for the "or equals" values as well (in your post above you have potential gaps... equals 0 and at equals 60--which could be a potential result).

Sincerely,

Sean

4 REPLIES 4
Collaborator

## Re: IF Statement / Switch Statement / IF, Else, Then

If I remember correct the switch step needs specific values like:

1->Connection1

30->Connection30

etc.

So after you get the EWT, do a calculation figuring out what case is the right case, set the new EWT and then pass that to your switch step.

david

Beginner

## Re: IF Statement / Switch Statement / IF, Else, Then

I don't think there is anything wrong with using nested IF statements.  There are fewer evaluation steps here than you think.  Only three, not four.

There isn't anything wrong with adding logic and another step item--Switch step.  It only counts against your total step count.

If all you are doing is playing a single prompt, save yourself a few steps.  ...just make sure you account for the "or equals" values as well (in your post above you have potential gaps... equals 0 and at equals 60--which could be a potential result).

Sincerely,

Sean

Beginner

Thanks!

## Re: IF Statement / Switch Statement / IF, Else, Then

The switch step will not do what you want, and you will need to use several if steps.

"An if-then-else statement can test expressions based on ranges of values or conditions, whereas a switch statement tests expressions based only on a single integer, enumerated value, or String object."

Alternatively, you could use a Do step, and write your own if then else block.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.