if and else

Example 1: Simple if:

var UserName = "John Smith"
if (UserName == "John Smith")
{
 welcomeImage.Show()
}

Example 2: If and an else

var totalScore = 75
if (totalScore >= 70)
{
 passImage.Show()
}
else
{
 failImage.Show()
}

Example 3: Nested if

var totalScore = 75
if (totalScore >= 70)
{
 if (totalScore >= 90)
 {
  honoursPassImage.Show()
 } else {
  passImage.Show()
 }
}
else
{
 failImage.Show()
}

Example 4: Multipart expression

This example tests to see if the user has scored 15 or more correct answers AND only attempted a maximum of 20 questions.

if ((SCORE_CORRECT >= 15)&&(SCORE_TOTAL<=20))
{
 passImage.Show()
}
else
{
 failImage.Show()
}

Close