Jump to content

Trying to understand the logic of the if and else statement


levanthai

Recommended Posts

Hey guys!

Thanks for your patience here... I know that I still have a lot to learn but I am trying to understand some of the basic of the if and else statement.... I have two separate codes and the first one is part of a longer code but not how to find out which part of the {} I should put the else statement, I guess I shouldn't be guessing at all.... thanks!

Link to comment
Share on other sites

Student was given assignment to RTFM.

Student was graded on assignment using a simple question/answer sheet.

Teacher graded students question/answer sheet and put grade into a variable called $student_grade

<

if($student_grade === "Passed"){

//student passed question/answer sheet so....

echo "Great job, you RTFM";

}

else{

//student failed question/answer sheet so....

echo "You did not RTFM";

}

>

Link to comment
Share on other sites

An if -else construct branches on the truthiness of the condition.

 

if (condition) {
  // This block executes if condition evaluates as TRUE
} else {
  // This block executes if condition evaluates as FALSE
}

Note that in PHP the condition must be enclosed within parens  ie.  ().  There is really nothing more to it than that.  If you have a more specific question, let us know.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.