# Homework Help: IF statement

1. Aug 26, 2010

### Travian

1. The problem statement, all variables and given/known data
I have a question regarding IF statements.

Here's an algorithm:

put on hat ;
IF (weather is sunny)
Put on sunglasses ;
ENDIF
Put on shoes ;

What items of clothing will be put on a) when it is raining and b) when it is sunny?

2. Relevant equations

3. The attempt at a solution

a) hat, shoes.
b) sunglasses, hat, shoes.

What i want to know is:

if its raining then obviously i put on a hat and shoes. Now if it's sunny (like indicated in the IF statement), then not only i wear sunglasses, but hat and shoes as well?

2. Aug 26, 2010

### xcvxcvvc

right. an if statement doesn't obliterate code surrounding it :)

It works like this: the code from the if to the end if is conditional. If the condition is true, the code within the if block executes. Otherwise, it skips it. Everything else in the program remains unchanged.

You can THINK of it like this (though i wouldn't ever put it like this on a test or anything. It's just to get the point across):

if rainy the code becomes:
put on hat ;
Put on shoes ;
and if sunny, the code becomes:
put on hat ;
Put on sunglasses ;
Put on shoes ;

3. Aug 26, 2010

### Travian

Thank you for confirmation:)