PHP Conditional Statements Quiz

TrustingPeridot avatar
TrustingPeridot
·
·
Download

Start Quiz

Study Flashcards

10 Questions

Conditional statements are useful for writing ______ making logic

decision

The if statement executes some code if one condition is ______

true

The if...else statement executes some code if a condition is true and another code if that condition is ______

false

The if...elseif...else statement executes different codes for more than two ______

conditions

PHP conditional statements are implemented by the following ______

types

Use the ______ statement to select one of many blocks of code to be executed. SYNTAX: ______ (n) { case label 1: code to be executed if n=label 1; break; case label 2: code to be executed if n=label 2; case label 3: code to be executed if n=label 3; … default: code to be executed if n is different from all labels; }

switch

Conditional ______ are used to perform different actions based on different conditions. Activity #5 write a program to check student grade based on marks whether A+, A, B, C, D grade or fail in PHP. Example: User input: 76 Output : D grade

statements

Activity #5 write a program to check student grade based on marks whether A+, A, B, C, D grade or fail in PHP. Example: User input: 76 Output : D grade NEXT TOPIC: LOOPING STRUCTURE PHP LOOPS.

perform

If( 1st condition) { Execute statement(s )if condition is true; } { ______( 2nd condition )Execute statement(s) if 2nd condition is true; }Else{ Execute statement(s) if both conditions are false; }

elseif

The switch statement is used to ______ different actions based on different conditions. Use the switch statement to select one of many blocks of code to be executed. SYNTAX: switch (n) { case label 1: code to be executed if n=label 1; break; case label 2: code to be executed if n=label 2; case label 3: code to be executed if n=label 3; … default: code to be executed if n is different from all labels; }

perform

Study Notes

Conditional Statements

  • Conditional statements are useful for writing logic making code
  • If statements execute some code if one condition is true
  • If...else statements execute some code if a condition is true and another code if that condition is false
  • If...elseif...else statements execute different codes for more than two conditions

Switch Statements

  • PHP conditional statements are implemented by the following: if, if...else, if...elseif...else, and switch statements
  • The switch statement is used to perform different actions based on different conditions
  • Syntax for switch statement: switch (n) { case label 1: code to be executed if n=label 1; break; ... default: code to be executed if n is different from all labels; }

PHP Program Example

  • Example program to check student grade based on marks: A+, A, B, C, D grade or fail
  • User input: 76, Output: D grade
  • If statements can be used to check conditions and execute specific code blocks based on the conditions

Conditional Statement Syntax

  • If statement syntax: If( 1st condition) { Execute statement(s) if condition is true; } { elseif( 2nd condition )Execute statement(s) if 2nd condition is true; } Else{ Execute statement(s) if both conditions are false; }

Test your understanding of PHP conditional statements with this quiz. Explore the importance of conditional statements, different types available in PHP, and their application in creating website logic.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Test je basiskennis over PHP met deze quiz!
6 questions
PHP Conditional Statements Quiz
21 questions
PHP Basics: Introduction and Syntax
12 questions
Web Development Lecture 9: PHP Loops and Functions
5 questions
Use Quizgecko on...
Browser
Browser