Jump to content


If - Else If - Else Statement


  • Please log in to reply
3 replies to this topic

#1 hime

hime

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 02 September 2010 - 05:54 AM

1. if - else if - else statement
2.switch statement

what will i do with this i cant understand it at all... can you teach me and help me with this thank you

#2 HistotechKev

HistotechKev

    Advanced Member

  • Members
  • PipPipPip
  • 45 posts
  • Gender:Male
  • Location:Pittsburgh, PA

Posted 02 September 2010 - 08:38 AM

QUOTE (hime @ Sep 2 2010, 05:54 AM) <{POST_SNAPBACK}>
1. if - else if - else statement
2.switch statement

what will i do with this i cant understand it at all... can you teach me and help me with this thank you


Dear Hime (Got your name):

Try adding some code as an example.

The following two lines are a basic "If, Else" written out, not using code.

If the cat is black, you can not see it on a dark night.

Else the cat will be visible and you will be able to see it.


The following two lines of code are a basic "If, Else, If, Else (All "If" statements must have an Else or some other possiable branch of logic. The next three lines are not code, but will show you how the logic works.

If the cat is black, you can not see it on a dark night.

Else, If the cat is a very dark colour, but not black, you may not see it.

Else the cat will be a light colour and you will be able to see it.


These branches of logic are like the roads in a city. If you have only one road you can only drive your car along that one road. Many roads allow you to drive to many destinations accross the city.

Without branch statement of the type "If" and "Else If" (there are others as well) computer progams would be almost useless because they could only ever complete one task.

Good luck.

Histotech Kev.



#3 hime

hime

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 03 September 2010 - 06:18 AM

QUOTE (HistotechKev @ Sep 2 2010, 04:38 PM) <{POST_SNAPBACK}>
Dear Hime (Got your name):

Try adding some code as an example.

The following two lines are a basic "If, Else" written out, not using code.

If the cat is black, you can not see it on a dark night.

Else the cat will be visible and you will be able to see it.


The following two lines of code are a basic "If, Else, If, Else (All "If" statements must have an Else or some other possiable branch of logic. The next three lines are not code, but will show you how the logic works.

If the cat is black, you can not see it on a dark night.

Else, If the cat is a very dark colour, but not black, you may not see it.

Else the cat will be a light colour and you will be able to see it.


These branches of logic are like the roads in a city. If you have only one road you can only drive your car along that one road. Many roads allow you to drive to many destinations accross the city.

Without branch statement of the type "If" and "Else If" (there are others as well) computer progams would be almost useless because they could only ever complete one task.

Good luck.

Histotech Kev.









thank you very much :)) thank you for helping me


#4 HistotechKev

HistotechKev

    Advanced Member

  • Members
  • PipPipPip
  • 45 posts
  • Gender:Male
  • Location:Pittsburgh, PA

Posted 06 September 2010 - 12:42 PM

QUOTE (hime @ Sep 2 2010, 06:54 AM) <{POST_SNAPBACK}>
1. if - else if - else statement
2.switch statement

what will i do with this i cant understand it at all... can you teach me and help me with this thank you

Dear Hime:
Sorry mate, I dont have the time or experience to teach anyone else, I have big gaps in my knoledge, you need to get a book. Look at my posts and get the book " Java An Introduction to Problem Solving and Programming (Fifth Edition"), that is the one I am using, and I like it,

Except for the sixth chapter, they should explain that constructiors work out on there own, when they can, which constructor to use when there are muliple, contstructors, because when you first read it you see all this and wonder how it knows which code to use or if the examples are different.  

Good luck.