Skip to main content

Posts

PHP Lesson 4

PHP Lesson 4: Control Structures (Decision Making and Loops) Welcome back! So far, our code executes line by line from top to bottom. Control structures allow us to change that flow, enabling our programs to be smart, responsive, and efficient. 1. Decision Making: The if...else Statement The if...else structure executes a block of code only if a specified condition is TRUE . The Basic Structure PHP <?php $score = 85 ; if ( $score >= 90 ) { echo "You got an A! Excellent work." ; } elseif ( $score >= 80 ) { // Check a secondary condition echo "You got a B! Great job." ; } else { // If all other conditions are FALSE echo "You need to study more." ; } // Output: You got a B! Great job. ?> Comparison Operators To create conditions within the if statement, you use comparison operators : Operator Name Example (returns TRUE) == Equal to 5 == 5 != Not equal to 5 != 10 > Greater th...