Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

can somebody explain me with simply words what an else if statement is?

.

3 Answers

Hi Eric, you should say "if-else-Statement", because the if always comes first. If-Else-Statement means your whole block of code starting with the if keyword and ending with the last brace of the else part. A statement in programming is simply one command you give to the program. var firstName = "Moritz" e.g. is also a statement.

does not really help but thank you. can you give me please an example like an example that contents all if-statements(if statements,else statements, is else statement)? thanks

An example would be:

// the statement starts here
if 4 > 4 {
    print("Magic!")
} else {
    print("Everything's okay!")
}
// and ends right here

Hello Erik:

"if-else" is a Conditional Statement. Meaning that some condition needs to pass so that a block of code can be executed. If we compare it to a real life scenario it could be something like this.

let myCar = "On"

if myCar == "On"{
    print("My Car is On")
} else {
    print("My Car is Off")
}

// It will print "My Car is On"

In the example above, you can translate it to. If myCar is On, then print "My Car is On", otherwise print "My Car Is Off". IN this case, since the "condition" is true, then it will execute the first code, if the condition is false, then it will execute the code inside the "else" statement.

I hope this helps you.

Good luck.