IF Statements: Should I Put On Sunglasses When It's Sunny?

  • Thread starter Travian
  • Start date
In summary, the IF statement in the given algorithm will result in the following items of clothing being put on: a) hat and shoes when it is raining, and b) sunglasses, hat, and shoes when it is sunny. The code surrounding the IF statement remains unchanged and the IF statement only affects the code within its block based on the given condition.
  • #1
Travian
64
0

Homework Statement


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?



Homework Equations





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?
 
Physics news on Phys.org
  • #2
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
Thank you for confirmation:)
 

Related to IF Statements: Should I Put On Sunglasses When It's Sunny?

1. Should I always wear sunglasses when it's sunny?

It is generally recommended to wear sunglasses when it's sunny, as the sun's UV rays can harm your eyes. However, it ultimately depends on personal preference and the intensity of the sunlight.

2. Can I wear any type of sunglasses when it's sunny?

It is important to choose sunglasses that offer UV protection and fit comfortably on your face. Look for sunglasses that block 99-100% of UVA and UVB rays.

3. What are the benefits of wearing sunglasses when it's sunny?

Sunglasses not only protect your eyes from harmful UV rays, but they also reduce glare and improve your visibility in bright sunlight. They can also prevent eye strain and headaches.

4. Is it necessary to wear sunglasses when it's cloudy but still bright outside?

Yes, it is still important to wear sunglasses when it's cloudy but bright outside. The sun's UV rays can still penetrate through clouds and cause damage to your eyes.

5. Can wearing sunglasses too often be harmful to my eyes?

No, wearing sunglasses when it's sunny is not harmful to your eyes. In fact, it can protect them from potential damage. However, it is important to take breaks from wearing sunglasses to allow your eyes to adjust to natural light.

Similar threads

  • Calculus and Beyond Homework Help
Replies
16
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
Replies
5
Views
1K
  • Introductory Physics Homework Help
Replies
4
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Advanced Physics Homework Help
Replies
14
Views
2K
  • Advanced Physics Homework Help
Replies
15
Views
1K
  • Calculus and Beyond Homework Help
Replies
2
Views
806
Back
Top