How to Mastering The JavaScript Switch Statement

The JavaScript switch statement is a way to make decisions in your code based on different conditions. It is a more organized and concise alternative to using multiple if-else statements. The switch statement evaluates a given expression, which can be a variable or a value, and compares it to several possible cases. If the value of the expression matches one of the cases, the associated code block (a set of instructions) is executed. If no match is found, an optional default case can be executed as a fallback, meaning it runs when none of the other cases apply.

For example, here’s a simple switch statement that checks the value of a variable called day:

switch (day) {
  case "Monday":
    console.log("Start of the work week! 😴");
    break;
  case "Friday":
    console.log("End of the work week! 🥳");
    break;
  default:
    console.log("A regular day");
}

By mastering switch statements, you can write cleaner, more efficient, and better-organized JavaScript code, ultimately improving your overall programming skills.

switch Statement Basics: Anatomy and structure

switch statements begins with the keyword switch, followed by an expression in parentheses. This expression is compared to a series of case labels enclosed in a switch block. Each case label represents a distinct value, and the code block that follows the case is executed when the expression matches the case label’s value. A break statement is typically used to exit the switch block after a matching case is executed, ensuring that only the intended code block runs, and preventing fall-through to the next cases. Optionally, a default case can be included to provide a fallback action when none of the case labels match the expression, ensuring a response for unknown values.

switch(expression) {
    case {value1}:
    // <-- Your Code to execute -->  
    break    // optional
    case {value2}:
    // <-- Your Code to execute -->   
    break    // optional
    default: // optional
    // <-- Code that executes when no values match-->
}

const superhero = 'Spider-Man';
switch (superhero) { 
  case 'Batman':
    console.log('🦇 The Dark Knight!');
    break;
  case 'Wonder Woman':
    console.log('👸 The Amazon Princess!');
    break;
  default:
    console.log('💥 There are so many amazing superheroes!');
}

switch vs. if-else

The switch statement is an alternative to using if-else statements when you have multiple conditions to handle. While if-else statements are suitable for checking a series of conditions that can be expressed as true or false, switch statements are more efficient when dealing with a single expression that can take on multiple distinct values. In essence, switch statements can make your code cleaner, more organized, and easier to read when you have several related conditions to manage.

For example, consider the following if-else structure:

if (color === "red") {
  console.log("The color is red 🟥");
} else if (color === "blue") {
  console.log("The color is blue 🟦");
} else if (color === "green") {
  console.log("The color is green 🟩");
} else {
  console.log("Unknown color 🌈");
}

The equivalent switch statement would look like this:

switch (color) {
  case "red":
    console.log("The color is red 🟥");
    break;
  case "blue":
    console.log("The color is blue 🟦");
    break;
  case "green":
    console.log("The color is green 🟩");
    break;
  default:
    console.log("Unknown color 🌈");
}

The switch statement offers a more organized and readable way to handle multiple conditions, particularly when dealing with a large number of cases. In a switch statement, the expression being evaluated is the variable or value inside the parentheses (in this example, the variable color).

When to use switch over if-else

  1. Large number of single-variable conditions: When you have a large number of conditions to handle, switch statements are generally more organized and easier to read than if-else chains.
  2. Single variable evaluation: If the conditions you are evaluating are based on a single variable or expression with multiple distinct values, switch statements can provide a more efficient and cleaner solution than if-else patterns.
  3. Faster code execution: In certain situations, JavaScript engines can optimize switch statements, leading to faster code execution when compared to a series of if-else statements.
  4. Easier maintenance: Switch statements make it easier to add, remove, or modify cases, as each case is self-contained within the switch block. In contrast, if-else chains may require more extensive modifications when changes are needed.
  5. Default fallback: Switch statements provide an optional default case that can be executed when none of the other cases match the given expression. This feature allows for a clean way to handle unexpected or unknown values.

When to use if-else over switch

  1. Complex conditions: If the conditions you are evaluating involve complex logic, multiple variables, or relational and logical operators, if-else patterns provide more flexibility and are better suited for these situations than switch statements.
  2. Range-based conditions: When you need to check for a range of values or conditions that are not discrete, if-else patterns offer a better solution, as switch statements are designed for comparing discrete values.
  3. Small number of conditions: If you have only a few simple conditions to check, using an if-else pattern can be more straightforward and easier to write than a switch statement.
  4. Non-constant cases: Switch statements require constant values for case labels, meaning they cannot be expressions that change at runtime. If you need to evaluate conditions with non-constant values, if-else patterns are the appropriate choice.
  5. Evaluating truthy or falsy values: If-else patterns are suitable when you need to check if a value is truthy or falsy. Switch statements are not designed for this type of evaluation and would require more verbose code to accomplish the same result.
  6. Early exit conditions: If you have an early exit condition where further evaluation is unnecessary once a certain condition is met, if-else patterns can be more efficient. With a switch statement, all cases are evaluated, even if an early match is found (unless you use a “break” statement).

Deciding on switch or if-else

Both switch and if-else solve similar problems and have advantages and disadvantages based on your use cases. To help you make your decision, I’ve created a simple switch statement:

switch (yourUseCase) {
  case 'large_number_of_conditions':
  case 'single_variable_evaluation':
  case 'multiple_discrete_values':
    console.log('Consider using a switch statement.');
    break;
  case 'complex_conditions':
  case 'range_based_conditions':
  case 'non_constant_cases':
    console.log('Consider using an if-else pattern.');
    break;
  default:
    console.log('Choose the most appropriate control structure based on your specific use case.');
}

switch Statement Functionality and Techniques:

The switch statement provides additional functionality and concepts that can be used to improve the performance, readability, and conciseness of your code.

The default case

The default case in a switch statement is executed when none of the other cases match the provided expression. It serves as a fallback to handle unexpected or unknown values, ensuring a response is provided even if there’s no matching case.

const beverage = 'lemonade';

switch (beverage) {
  case 'coffee':
    console.log('☕️ Enjoy your coffee!');
    break;
  case 'tea':
    console.log('🍵 Have a relaxing cup of tea!');
    break;
  default:
    console.log('🥤 Your choice of drink is not listed, but cheers anyway!');
}

The break keyword

The break keyword is used in a switch statement to exit the switch block once a matching case is found and executed. It prevents the code from continuing to execute the remaining cases, ensuring only the correct output is generated.

const transport = 'bike';

switch (transport) {
  case 'car':
    console.log('🚗 Drive safely!');
    break;
  case 'bike':
    console.log('🚲 Enjoy your bike ride!');
    break;
  case 'bus':
    console.log('🚌 Have a pleasant bus journey!');
    break;
}

The Fall-Through technique

A case cannot have more than one condition in a switch statement. To incorporate multiple conditions in one case, consider using the fall-through technique. Not only does it save you time, it ensure you don’t repeat yourself.

Fall-through in a switch statement occurs when you intentionally omit the break keyword in a case, allowing the code execution to continue to the next case(s) until a break is encountered or the end of the switch block is reached. This can be useful when multiple cases share the same output or action.

const clothing = 'jacket';

switch (clothing) {
  case 't-shirt':
  case 'shorts':
    console.log('😎 Looks like it\'s warm outside!');
    break;
  case 'jacket':
  case 'sweater':
    console.log('❄️ Bundle up, it\'s cold!');
    // No break, fall-through to the next case
  case 'scarf':
    console.log('🧣 Don\'t forget your scarf!');
    break;
}

Common issues and pitfalls

Multiple cases executing (Forgetting to use the break statement)

A frequent mistake when using switch statements is not including the break statement after each case. This error results in unintentional fall-through, executing multiple cases instead of just the desired one.

How to fix it: Add a break statement after each case to prevent fall-through.

const mood = 'happy';

switch (mood) {
  case 'happy':
    console.log('😀 Keep smiling!');
    // <--- Missing break statement
  case 'sad':
    console.log('☹️ Cheer up!');
    break;
  case 'angry':
    console.log('😠 Take a deep breath!');
    break;
}

// --Output-- 
//😀 Keep smiling! 
//☹️ Cheer up!

Incorrect Comparison Values and Types

Switch statements use strict comparison, which can lead to unexpected results when comparing different data types. In the example below, the string "2" is not equal to the number 2. This pitfall might cause your cases not to execute as intended.

How to fix: Consider the type of your variables and remember it will be evaluated strictly. TypeScript may help if you’re working on larger projects.

const numOfPets = '2';

switch (numOfPets) {
  case 2: // Because '2' !== 2
    console.log('🐾 Double the fun!');
    break;
  default:
    console.log('🐾 Share the love!');
}

// -- Output --
// 🐾 Share the love!

Scoping issues

A common pitfall in switch statements is declaring variables without block scope or incorrect scopes, causing them to be accessible in other cases, or creating syntax errors. You may experience an Uncaught SyntaxError: ... if you try to redeclare the same variable in multiple clauses.

The fixes:

  • For common variables you intend to use in all cases, declare it with let before your switch statement, or;
  • Scope your clauses as block scope (i.e. wrap your clauses with parentheses { ... })

Block scope your clauses:

// The problem: 
switch (weather) {
  case 'rain':
    const notification = '🌦️ ️Rainy days can be cozy!';
    console.log(notification);
    break;
  case 'thunder':
    // 'notification' is still accessible here
    console.log(notification + ' ⚡ Be careful!');
    break;
}
// Fix 1: Use Block Scope when declaring
switch (weather) {
  case 'rain': { // <-- look here.
    const notification = '🌦️ ️Rainy days can be cozy!';
    console.log(notification);
    break;
  }
  case 'thunder': {
    const notification = '⚡ Be careful!';
    console.log(notification);
    break;
  }
}

// Fix 2: Declare it with let before your statement
let notification = '' // <-- look here.
switch (weather) 
  case 'rain':
    notification = '🌦️ ️Rainy days can be cozy!';
    console.log(notification);
    break;
  case 'thunder':
    notification = '⚡ Be careful!';
    console.log(notification);
    break;
}

Conclusion

Now that you know what a switch statement is, how it works, and when to use it, it’s time to start implementing it! I hope you’ve enjoyed this article. Join us over on the SitePoint Community if you have any questions about this piece or JavaScript in general.

Original article source at: https://www.sitepoint.com/

#javascript #switch #statement 

How to Mastering The JavaScript Switch Statement

SQL Select: Statement and Query Examples

Structured Query Language (SQL) is a programming language that you use to manage data in relational databases. You can use SQL to create, read, update, and delete (CRUD) data in a relational database.

You can write SQL queries to insert data with INSERT, read data with SELECT, update with UPDATE, and delete data with DELETE.

This article will teach you how to write SQL SELECT queries. You'll learn the various ways you can write these queries, and what the expected results should be.

How to Use the SQL SELECT Statement

You can use the SQL SELECT statement to retrieve data from a database table that has been specified.

You can write your statement in various ways to get the exact data you want. These data are extracted from the database table and returned as a table.

// Syntax

SELECT expression(s)
FROM table(s)
[WHERE condition(s)]
[ORDER BY expression(s) [ ASC | DESC ]];

The preceding code is a very detailed syntax that encompasses a lot of information that I'll explain with examples.

Let's begin by going over the parameters and arguments:

  • expression(s): This represents the column(s) whose data you want to retrieve or the entire table's columns using an asterisk (*).
  • table(s): The name of the table(s) from which you want to retrieve records. The FROM clause must include at least one table.
  • WHERE condition(s): This is an optional field. This allows you to specify a condition that will guide the data that is retrieved for the specified column(s). If no conditions are specified, all records will be chosen.
  • ORDER BY expression(s): This is an optional field. This allows you to declare a column whose data will be used to sort the results. A comma should separate the values if you provide more than one expression.
  • ASC: This is an optional expression value. ASC sorts the result set by expression in ascending order. If this is not specified, this is the default behavior.
  • DESC: This is an optional expression value. DESC sorts the result set by expression in descending order.

SQL Select Queries

Suppose you have a database with the name "Users" and has the following data:

USER_IDFIRST_NAMELAST_NAMEAGESTATUS
1JohnDoe33Married
2AliceTruss23Single
3DavidBohle56Married
4AaronBen34Single
5LouisVic72Married
6CharlesChris19Single

Let's now explore various queries and see how they work.

SQL Select All

You might need to select all the columns from a database. Instead of listing each column, you can use the asterisk (*) character.

SELECT *
FROM Users;

Here is what your output will look like when you make use of this command on the user's table:

s_620D0D0A23556D1CE834866DA826B5C1B0E55BD04F998B1718541CB54692E6CA_1666430594839_Untitled.drawio+19

SQL Select Specified Columns

You can also fetch specified columns instead of all the columns by listing the columns and separating them by a comma:

SELECT first_name, last_name
FROM Users;

Here is what your output will look like when you make use of this command on the user's table:

s_620D0D0A23556D1CE834866DA826B5C1B0E55BD04F998B1718541CB54692E6CA_1666441467406_Untitled.drawio+27

SQL Select WHERE Clause

You may want to return only rows that satisfy a specific condition. This condition can be specified using the optional WHERE clause. The WHERE clause allows you to retrieve records from a database table that match a given condition(s).

For example, suppose you only want to fetch users whose status is "single":

SELECT *
FROM Users
WHERE status = 'Single';

Here is what your output will look like when you make use of this command on the user's table:

s_620D0D0A23556D1CE834866DA826B5C1B0E55BD04F998B1718541CB54692E6CA_1666431175784_Untitled.drawio+21

Generally, the WHERE clause is used to filter the results. You can also use common operators like =, which you used, and others like <, >, <=, >=, AND, BETWEEN, and IN.

SELECT Using Equality Operators

Suppose you want to fetch only users whose age is greater than 30. Then your query will be:

SELECT *
FROM Users
WHERE age > 30;

Here is what your output will look like when you make use of this command on the user's table:

s_620D0D0A23556D1CE834866DA826B5C1B0E55BD04F998B1718541CB54692E6CA_1666431269376_Untitled.drawio+22

You can also use other equality operators like <, <=, and >=.

SELECT Using the AND Operator

You might often want to use more than one condition to filter the table's contents. You can do this with the AND operator.

SELECT *
FROM Users
WHERE status = 'Single' AND age > 30;

Here is what your output will look like when you make use of this command on the user's table:

s_620D0D0A23556D1CE834866DA826B5C1B0E55BD04F998B1718541CB54692E6CA_1666433362143_Untitled.drawio+23

SELECT Using the BETWEEN Operator

You use the BETWEEN operator to get the range of data you want to filter. You can decide to use the equality and AND operator, but BETWEEN provides a better syntax.

SELECT *
FROM Users
WHERE age BETWEEN 20 AND 30;

Here is what your output will look like when you make use of this command on the user's table:

s_620D0D0A23556D1CE834866DA826B5C1B0E55BD04F998B1718541CB54692E6CA_1666433680877_Untitled.drawio+24

SELECT Using the IN Operator

Also, the IN operator lets you set more than one exact basis for filtering each row. For example, you can fetch only rows whose value is in the bracket defined:

SELECT *
FROM Users
WHERE age IN (56,33,10);

Here is what your output will look like when you make use of this command on the user's table:

s_620D0D0A23556D1CE834866DA826B5C1B0E55BD04F998B1718541CB54692E6CA_1666433956123_Untitled.drawio+26

SQL Select ORDER BY Clause

So far, you have learned how to fetch from your table with SQL, but you will notice that these data always follow the original order. You can adjust the order in which the data is fetched using the ORDER BY clause.

Two major options are Ascending (ASC) and descending (DESC) order. For example, you might want your table's rows to be arranged in ascending order based on the first_name:

SELECT *
FROM Users
ORDER BY first_name ASC;

Here is what your output will look like when you make use of this command on the user's table:

s_620D0D0A23556D1CE834866DA826B5C1B0E55BD04F998B1718541CB54692E6CA_1666441975760_Untitled.drawio+28

Note: You can always combine these options and clauses in one query to fetch exactly what you want.

Wrapping up!

In this article, you learned how to use the SQL SELECT query to retrieve data from a relational database. Other options are available, but these are the ones you'll most likely use regularly.

Have fun coding!

Original article source at: https://www.freecodecamp.org/

#sql #query #statement 

SQL Select: Statement and Query Examples
Gordon  Murray

Gordon Murray

1668748920

How to Bash Continue Built-In Statement

“In bash, the continue built-in statement functions as a control statement. Program control is passed to the next iteration unless specified in the enclosing loop body for the current iteration. This concept appears in bash along with other programming languages.

However, it is always hard for a beginner to learn the bash continue statement. So if you are also looking for simple ways to learn it, this tutorial is for you. This tutorial will give you a brief on the bash continue built-in statement with various examples.”

Bash Continue Built-In Statement

The bash continue built-in statement resumes the iteration of an enclosing loop such as while, for, select, or until. It has meaning only when it applies to loops. Its general syntax is :

continue < n >

 
In the above syntax, n denotes an integer value whose default value is 1. This integer value represents the depth of the continue statement. Execution continues on the loop control of the nth enclosing loop when n numbers are given, i.e., you can start the outer loop statement by increasing the integer value.

Resumes an Iteration in Different Loops With Continue Built-In Statement

In bash, you can use the continue statement in different loops. It depends on the loop type whether the program restarts or starts over.

Continue Built-in Statement in For Loop

The controlling variable takes the next element in the list as its value within the “for” loop. We have taken numbers from 3 to 60 under the for loop in the following script. Here, through the continue statement, we print out those numbers divisible by 10 and continue the loop.


In the following output, you can see that only those numbers from 3 to 60 are printed, which are divisible by 10.

Continue Built-in Statement in While Loop

When you use the continue statement in “until” and “while” constructions, the system resumes the execution with the command at the top of the loop.

This while loop starts with 25 numbers and continues until the value of n reaches 15 in the loop. Under this loop, if the value of n is less than 19, it prints that number along with the “class.”


On running the above script, you will get the blow output.

Continue Built-in Statement Until Loop

Compared to the while loop, the until loop is not much different. In the same way, it works. In the following until loop example, numbers will be added starting from 25 and will continue until n exceeds 13. Under this loop, if the value of n is more than 17, it will print with the number “You are not an adult.”


You will get the following output after running the above script.

Wrapping Up

You use the bash continue built-in statement when you want to leave the loop partially but skip a code when the input meets a specific condition. The continue statement passes the control back to the loop statement for the next iteration, except for executing the code when a defined condition is met.

Original article source at: https://linuxhint.com/

#bash #statement 

How to Bash Continue Built-In Statement
Gordon  Taylor

Gordon Taylor

1668504846

How to Use JavaScript If Statement To Create Conditions

JavaScript if statement explained (single and multiple conditions example)

Learn How to use JavaScript if statement to create conditions.

The if statement is one of the building blocks of JavaScript programming language.

The statement is used to create a conditional branch that runs only when the condition for the statement is fulfilled.

To use the if statement, you need to specify the condition in parentheses:

if (10 > 5) {
  console.log("Ten is bigger than five");
}

When the expression inside the parentheses of the if statement evaluates to true, the code specified in the statement body is executed.

You define an if statement body using the curly brackets ({}) like a function.

In the above code, the expression of 10 > 5 evaluates to true, so the console.log is executed by JavaScript.

When you specify an expression that evaluates to false, the code inside the if block won’t be executed.

Nothing happens when you run the code below:

if (10 > 70) {
  console.log("Ten is bigger than seventy");
}

When you have only one line of code to run in the if statement, you can omit the curly brackets from the statement.

Write the code you want to run next to the parentheses as shown below:

if (10 > 5) console.log("Ten is bigger than five");

The above code will run without any issue.

You can use variables as part of the condition for the if statement as follows:

let occupation = "Programmer";

if (occupation === "Programmer") {
  console.log("Your are a Programmer!");
}

You can replace the values used in the if condition with variables and constants.

Next, let’s see how you can define multiple conditions in an if statement.

Defining multiple conditions in Javascript if statement

Up to this point, you’ve seen how to create a JavaScript if statement with a single condition:

if (10 > 70) {
  console.log("Ten is bigger than seventy");
}

if (10 > 3) {
  console.log("Ten is bigger than three");
}

When you have multiple requirements for the code to run, you can actually specify multiple conditions inside parentheses.

The code below has an if statement with two conditions:

let num = 50;

if (num > 10 && num < 90) {
  console.log("Number is between 10 and 90");
}

The AND operator (&&) above is used to specify two conditions for the if statement to run.

When the expressions evaluate to true, then Javascript will execute the body of the if statement.

You can specify as many conditions as you need using the AND or OR (||) operator.

When using the OR operator, the code will be run if one of the conditions evaluate to true as follows:

let num = 25;

if (num === 10 || num === 25) {
  // true so code below will be executed
  console.log("Number is either 10 or 25");
}

When using the AND operator, all conditions must evaluate to true for the code to run.

By default, JavaScript will evaluate if statement conditions from left to right.

Depending on the result you want to have, you can modify the evaluation order by using parentheses as shown below:

let num = 20;
let str = "xyz";

// 1. No parentheses between conditions

if ((num == 25 && str == "abc") || str == "xyz") {
  console.log("first if statement");
}

// 2. Parentheses for the `str` evaluation

if (num == 25 && (str == "abc" || str == "xyz")) {
  console.log("second if statement");
}

In the code above, the first if statement will be executed while the second will be ignored.

This is because the first if statement evaluates to true with the following steps:

# first if statement
num == 25 && str == "abc" || str == "xyz"
          👆              ||     👆
        false            ||    true

The expression false || true evaluates to true so the code is executed.

In the second if statement, the expression inside parentheses will be executed first as shown below:

# second if statement
num == 25 && (str == "abc" || str == "xyz")
                           👆
num == 25 &&              true

The expression num == 25 && true evaluates to false because the num value is 20 in the example above. The second if statement is ignored because of this.

And that’s how you can specify multiple conditions with the if statement.

You can define as many conditions as you need for your if statement, but keep in mind that too many conditions may cause confusion.

Try to keep the conditions as minimum as you can.

Finally, you can also pair the if statement with an else statement.

Learn more here: JavaScript if and else statements

Great work on learning about the JavaScript if statement. 👍

Original article source at: https://sebhastian.com

#javascript #statement #single #multiple 

How to Use JavaScript If Statement To Create Conditions
Desmond  Gerber

Desmond Gerber

1668502876

Bash Continue Built-In Statement

“In bash, the continue built-in statement functions as a control statement. Program control is passed to the next iteration unless specified in the enclosing loop body for the current iteration. This concept appears in bash along with other programming languages.

However, it is always hard for a beginner to learn the bash continue statement. So if you are also looking for simple ways to learn it, this tutorial is for you. This tutorial will give you a brief on the bash continue built-in statement with various examples.”

Bash Continue Built-In Statement

The bash continue built-in statement resumes the iteration of an enclosing loop such as while, for, select, or until. It has meaning only when it applies to loops. Its general syntax is :

continue < n >

In the above syntax, n denotes an integer value whose default value is 1. This integer value represents the depth of the continue statement. Execution continues on the loop control of the nth enclosing loop when n numbers are given, i.e., you can start the outer loop statement by increasing the integer value.

Resumes an Iteration in Different Loops With Continue Built-In Statement

In bash, you can use the continue statement in different loops. It depends on the loop type whether the program restarts or starts over.

Continue Built-in Statement in For Loop

The controlling variable takes the next element in the list as its value within the “for” loop. We have taken numbers from 3 to 60 under the for loop in the following script. Here, through the continue statement, we print out those numbers divisible by 10 and continue the loop.


In the following output, you can see that only those numbers from 3 to 60 are printed, which are divisible by 10.

Continue Built-in Statement in While Loop

When you use the continue statement in “until” and “while” constructions, the system resumes the execution with the command at the top of the loop.

This while loop starts with 25 numbers and continues until the value of n reaches 15 in the loop. Under this loop, if the value of n is less than 19, it prints that number along with the “class.”


On running the above script, you will get the blow output.

Continue Built-in Statement Until Loop

Compared to the while loop, the until loop is not much different. In the same way, it works. In the following until loop example, numbers will be added starting from 25 and will continue until n exceeds 13. Under this loop, if the value of n is more than 17, it will print with the number “You are not an adult.”

You will get the following output after running the above script.

Wrapping Up

You use the bash continue built-in statement when you want to leave the loop partially but skip a code when the input meets a specific condition. The continue statement passes the control back to the loop statement for the next iteration, except for executing the code when a defined condition is met.

Original article source at: https://linuxhint.com/

#bash #statement #functions 

Bash Continue Built-In Statement

Comprender La Declaración Del Interruptor En Power Automate

En general, para manejar múltiples condiciones como en javascript y C#, se usará el conmutador .net. Podemos usar la acción Switch de la misma manera en Power automatic. En este artículo, podemos ver cómo se puede usar para decidir si una persona puede vacunarse o no.

Paso 1

Inicie sesión en el entorno de Power Apps requerido utilizando la URL make.powerapps.com proporcionando el nombre de usuario y la contraseña y haga clic en Flujos en el lado izquierdo como se muestra en la figura a continuación.

Comprender la declaración de cambio en Power Automate

Paso 2

Después del paso 1 , haga clic en Nuevo flujo y seleccione flujo de nube instantáneo y proporcione el disparador como Activar manualmente un flujo y haga clic en Crear como se muestra en la siguiente figura.

Comprender la declaración de cambio en Power Automate

Paso 3

Después del Paso 2 , nombre el flujo como Instrucción de cambio de comprensión y en Desencadenar manualmente proporcione valores de entrada como

Title : Enter Age
 Value : Number

BÁSICO

como se muestra en la siguiente figura.

Comprender la declaración de cambio en Power Automate

Paso 4

Después del paso 3 , realice la acción de inicializar variable y proporcione los valores que se muestran a continuación

Name : Age
Type : Integer
Value : @{triggerBody()['number']} [ From Step 3]

BÁSICO

como se muestra en la siguiente figura.

Comprender la declaración del interruptor en Power Automate Figura 4

Paso 5

Después del paso 4 , realice la acción de cambio y proporcione el valor

On : @{variables('Age')}

BÁSICO

y en una parte de Case proporciona el valor como

Equals 19

BÁSICO

 y tomar una función de composición y proporcionar las entradas como

Inputs : Can take vaccine

BÁSICO

como se muestra en la siguiente figura.

Comprender la declaración de cambio en Power Automate

Paso 6

Después del Paso 5 , tome otra sección del caso y asígnele el nombre Caso 2 y proporcione

Equals : 7

BÁSICO

Y tomar acción de redacción y proporcionar entradas como

Inputs : Cannot take vaccine

BÁSICO

como se muestra en la siguiente figura.

Comprender la declaración del interruptor en Power Automate Figura 6

Paso 7

Después del paso 6 , en la declaración de cambio en la sección predeterminada, realice una acción de redacción y proporcione las entradas como

Inputs : Thanks for your interest , please wait for our message.

BÁSICO

como se muestra en la siguiente figura.

Comprender la declaración de cambio en Power Automate

Paso 8

Después del Paso 7 , ahora guarde y pruebe el flujo y proporcione el valor como 19, debería ver que la primera parte del caso se ejecutará como se muestra en la figura a continuación.

Comprender la declaración de cambio en Power Automate

Paso 9

Después del Paso 8 , ahora guarde y pruebe el flujo y proporcione el valor como 78, debería ver que la sección predeterminada del interruptor se ejecutará como se muestra en la figura a continuación.

Comprender la declaración de cambio en Power Automate

Nota

  1. Al igual que una caja de interruptores normal, se pueden manejar todas las opciones de la caja.

Conclusión

De esta manera, podemos usar fácilmente la acción del interruptor para manejar diferentes condiciones en la automatización de energía. 

Fuente: https://www.c-sharpcorner.com/article/understand-switch-statement-in-power-automate/

#powerautomate #statement 

Comprender La Declaración Del Interruptor En Power Automate
高橋  花子

高橋 花子

1649837789

PowerAutomateのSwitchステートメントを理解する

通常、javascriptやC#のように複数の条件を処理するには、.netスイッチが使用されます。電源自動化でも同じようにスイッチアクションを使用できます。この記事では、人が予防接種を受けることができるかどうかを決定するためにそれをどのように使用できるかを見ることができます。

ステップ1

次の図に示すように、 URL make.powerapps.comを使用してユーザー名とパスワードを入力し、左側の[フロー]をクリックして、必要なPowerApps環境にログインします。

PowerAutomateのSwitchステートメントを理解する

ステップ2

ステップ1の後、[新しいフロー]をクリックし、インスタントクラウドフローを選択して、トリガーを手動でトリガーし、次の図に示すように[作成]をクリックします。

PowerAutomateのSwitchステートメントを理解する

ステップ3

ステップ2の後、フローに「Understand Switch Statement」という名前を付け、「手動でトリガー」で入力値を次のように指定します。

Title : Enter Age
 Value : Number

ベーシック

下の図に示すように。

PowerAutomateのSwitchステートメントを理解する

ステップ4

手順3の後、変数の初期化アクションを実行し、次のように値を指定します

Name : Age
Type : Integer
Value : @{triggerBody()['number']} [ From Step 3]

ベーシック

下の図に示すように。

PowerAutomateのSwitchステートメントを理解する図4

ステップ5

ステップ4の後、スイッチアクションを実行し、値を指定します

On : @{variables('Age')}

ベーシック

ケースの一部では、次のように値を提供します

Equals 19

ベーシック

 合成関数を取り、入力を次のように提供します

Inputs : Can take vaccine

ベーシック

下の図に示すように。

PowerAutomateのSwitchステートメントを理解する

ステップ6

手順5の後、別のケースセクションを取得し、ケース2という名前を付けて、次のように入力します。

Equals : 7

ベーシック

そして、作成アクションを実行し、次のように入力を提供します

Inputs : Cannot take vaccine

ベーシック

下の図に示すように。

PowerAutomateのSwitchステートメントを理解する図6

ステップ7

ステップ6の後、デフォルトセクションのswitchステートメントで、作成アクションを実行し、次のように入力を提供します。

Inputs : Thanks for your interest , please wait for our message.

ベーシック

下の図に示すように。

PowerAutomateのSwitchステートメントを理解する

ステップ8

ステップ7の後、フローを保存してテストし、値を19として指定します。次の図に示すように、最初のケースの部分が実行されることがわかります。

PowerAutomateのSwitchステートメントを理解する

ステップ9

ステップ8の後、フローを保存してテストし、値を78として指定します。次の図に示すように、スイッチのデフォルトセクションが実行されるはずです。

PowerAutomateのSwitchステートメントを理解する

ノート

  1. 通常のスイッチケースと同じように、すべてのケースオプションを処理できます。

結論

このようにして、スイッチアクションを簡単に使用して、電力自動化のさまざまな条件を処理できます。 

出典:https ://www.c-sharpcorner.com/article/understand-switch-statement-in-power-automate/ 

#powerautomate #statement 

PowerAutomateのSwitchステートメントを理解する
Dylan  Hahn

Dylan Hahn

1649161560

Python Tutorials: If Statement For Beginners (2022)

If Statement

It uses the if keyword, followed by the condition.

Syntax:

if condition:

#statement to execute if the condition is true

Below is the entire workflow of how if statements work:

test-expression

First, the test expression is checked. If the expression is true, the body of the if the statement is executed. If it is false, the statement present after the if statement is executed. In either case, any line of code present outside if the statement is evaluated by default.

To understand this better, we’ll use an example:

a=20

if a>50:

    print("This is the if body")

print("This is outside the if block")

Since 20 is not greater than 50, the statement present inside the if block will not execute. Instead, the statement present outside the if block is executed.

if-block.

In the code below, both the print statements will be executed since a is greater than 50.

outside-if

So far, we could specify the statements that will be executed if a condition is true. Now, if you want to evaluate statements that determine whether a condition is actual and if a separate set of statements is false, you can use the if-else conditional statement.

#python 

Python Tutorials: If Statement For Beginners (2022)

Best Practices of Using IMPORT Statement

In this video, we can learn best practices of using the import statement
1. Order of the import statements
2. Avoid long relative paths to the files.
3. Import what is necessary at that point.

For More Videos:
Essentials for Web Developers: https://www.youtube.com/watch?v=9uGuG2L08W0&list=PL20fyMtMStyGltl7wjgwSoKM_PmhB6J1v

Interview Questions: https://www.youtube.com/watch?v=Omu272bMBlk&list=PL20fyMtMStyEK2gggQurRKZMpbwgiMh-1

Best Practises & Common Mistakes: https://www.youtube.com/watch?v=Qtrl0OEzvMo&list=PL20fyMtMStyHL0uMGRLACViz8-04mhxcC

Reactjs beginner Playlist: https://www.youtube.com/watch?v=SkevBJhRV4M&list=PL20fyMtMStyFsrTQAjqc4QpkpCqrR3qN1

#statement #import

Best Practices of Using IMPORT Statement
Eldora  Bradtke

Eldora Bradtke

1596446520

What is an expression and what is a statement in JavaScript 

In JavaScript we have expression and statement. Even though I read the definition about it multiple times, after a while, I still forget which one is which. So, this post is a reminder for everyone like me who confuses these two, so you will never forget it but always keep in mind the difference between expression and statement.

Image for post

Photo by bruce mars on Unsplash

A JS expression is any valid code that resolves into a value and can be written whenever you would expect a value. Usually expression are written in only one line. For example:

  • 42 // a number
  • “Hello World” // a string
  • 42 + 1 // a calculation
  • x = 42 + 1 // calculation
  • myVar // a variable
  • myFun() // a function that returns a value

But it’s more complicated than you think . There are different types of expressions:

  • Arithmetic: Resolves to a number, e.g.

42

42 + 1

etc.

  • String: Resolves to a string, e.g.

"Hello World"

"123"

etc.

#difference-between #difference #statement #expression #javascript #programming

What is an expression and what is a statement in JavaScript 
Annalise  Hyatt

Annalise Hyatt

1595044200

Bash if..else Statement

In this tutorial, we will walk you through the basics of the Bash if statement and show you how to use it in your shell scripts.

Decision making is one of the most fundamental concepts of computer programming. Like in any other programming language, ifif..elseif..elif..else and nested if statements in Bash can be used to execute code based on a certain condition.

if Statement

Bash if conditionals can have different forms. The most basic if statement takes the following form:

if TEST-COMMAND
then
  STATEMENTS
fi

Copy

The if statement starts with the if keyword followed by the conditional expression and the then keyword. The statement ends with the fi keyword.

If the TEST-COMMAND evaluates to True, the STATEMENTS gets executed. If TEST-COMMAND returns False, nothing happens, the STATEMENTS gets ignored.

In general, it is a good practice to always indent your code and separate code blocks with blank lines. Most people choose to use either 4-space or 2-space indentation. Indentations and blank lines make your code more readable and organized.

Let’s look at the following example script that checks whether a given number is greater than 10:

#!/bin/bash

echo -n "Enter a number: "
read VAR

if [[ $VAR -gt 10 ]]
then
  echo "The variable is greater than 10."
fi

Copy

Save the code in a file and run it from the command line:

bash test.sh

#bash #statement

Bash if..else Statement