In: Computer Science
1. Write a simple batch include IFELSE statments?
2. Write a simple Powershell Script with IFELSE statements?
3. Explain this powershell script and write its output?
$x = 30
if($x -eq 10){
write-host("Value of X is 10")
} elseif($x -eq 20){
write-host("Value of X is 20")
} elseif($x -eq 30){
write-host("Value of X is 30")
} else {
write-host("This is else statement")
}
1. Write a simple batch include IFELSE statements?
syntax:If (condition) (do_something) ELSE (do_something_else)
Example SET /A a = 5 SET /A b = 10 SET /A c = %a% + %b% if %c%==15 (echo "The value of variable c is 15") else (echo "Unknown value") if %c%==10 (echo "The value of variable c is 10") else (echo "Unknown value")
2. Write a simple Powershell Script with IFELSE statements?
Syntax:
Following is the syntax of an if...else statement −
if(Boolean_expression) {
// Executes when the Boolean expression is true
}else {
// Executes when the Boolean expression is false
}
Example
$x = 30
if($x -le 20){
write-host("This is if statement")
}else {
write-host("This is else statement")
}
The output ->This is else statement
3. Explain this PowerShell script and write its output?
$x = 30
if($x -eq 10){
write-host("Value of X is 10")
} elseif($x -eq 20){
write-host("Value of X is 20")
} elseif($x -eq 30){
write-host("Value of X is 30")
} else {
write-host("This is else statement")
}
Ans: output is->Value of X is 30