Home >Common Problem >What are the three forms of conditional statements?

What are the three forms of conditional statements?

小老鼠
小老鼠Original
2024-01-11 13:37:302084browse

Three forms of conditional statements: 1. if statement: the syntax is "if (condition) {execution statement}", if the condition is true, the statement is executed; 2. if-else statement: the syntax is " if (condition) {Execute statement 1} else {Execute statement 2}", if the condition is true, execute statement 1; otherwise, execute statement 2; 3, switch statement, etc.

What are the three forms of conditional statements?

The three forms of conditional statements are as follows:

  1. if statement:

    • Syntax: if (condition) {Execute statement}
    • If the condition is true, execute the statement.
  2. if-else statement:

    • Syntax: if (condition) { Execute statement 1 } else { Execute statement 2 }
    • If the condition is true, execute statement 1; otherwise, execute statement 2.
  3. switch statement:

    • Syntax: switch (expression) { case value 1: execute statement 1; break; case value 2: execute Statement 2; break; ... default: execution statement; }
    • According to the value of the expression, select and execute the statement following the corresponding case. If there is no matching value, the statement following default is executed.

The above are three common forms of conditional statements, each form has its specific usage scenarios and functions.

The above is the detailed content of What are the three forms of conditional statements?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn