T
T
TechNOIR2018-08-20 11:40:47
PowerShell
TechNOIR, 2018-08-20 11:40:47

Powershell. How to use switch on two variables?

Good afternoon.
Can you please tell me if it is possible to use switch for two variables? Instead of if
I have variables in two functions. In one $a in another $b. They take values ​​either true or false according to body movements in functions.
In the third function, I take actions based on the values ​​of $a and $b
I would like to understand if switch can be used instead of if here?
Conditions to be handled:
1. $a=true and $b=true
2. $a=false and $b=false
3. 1. $a=false and $b=true
1. $a=true and $b=false
thanks in advance

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
ApeCoder, 2018-08-20
@ApeCoder

switch([System.Tuple]::Create($true, $false))
{
     ([System.Tuple]::Create($true, $true))  {"1"}
     ([System.Tuple]::Create($true, $false))  {"2"}
}

A
anykey_ua, 2018-08-20
@anykey_ua

Good afternoon!
As an option, give the sum of values ​​​​to the Switch input (example below), but it will be necessary to modify the variables at the output of the first two functions in order to exclude the coincidence of the results of their sum
$a = 0
$b = 0
switch ($a+$b){
0 {Write -Host "0";break}
1 {Write-Host "1";break}
2 {Write-Host "2";break}
}

A
Alexander, 2018-08-20
@asand3r

You can use a nested switch.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question