School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 309,245 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,669 people online right now. Registration is fast and FREE... Join Now!




how to know when to use which statement

 

how to know when to use which statement, psuedocode

confusedbycode

16 Apr, 2009 - 04:39 PM
Post #1

New D.I.C Head
*

Joined: 16 Apr, 2009
Posts: 6

I get the set as real,
I am lost on when to use Case,
or While, or then.
Can anyone help clear my confusion?
Thanks, blink.gif

User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 4)

Core

RE: How To Know When To Use Which Statement

16 Apr, 2009 - 05:18 PM
Post #2

The .NET Dude
Group Icon

Joined: 8 Dec, 2008
Posts: 3,054



Thanked: 218 times
Dream Kudos: 900
Expert In: C#, VB.NET, WPF, .NET Framework

My Contributions
It really depends on the situation. You should see more information on how those statements are used in different situations and pick the most effective one.

I'm going to give a simple example - I was working on an application in which the user picked either a YES or NO response. Therefore, I needed somehow to check which one was selected. I used the IF statement, since there are only two choices. But if I would have to choose between YES, NO, I Don't Know and Ignore Question, then I would use Select Case, since there are more verification parameters.
User is offlineProfile CardPM
+Quote Post

liyam

RE: How To Know When To Use Which Statement

16 Apr, 2009 - 10:49 PM
Post #3

New D.I.C Head
*

Joined: 16 Apr, 2009
Posts: 2



Thanked: 1 times
My Contributions
Actually, it depends on preference.

if you can use nested if else statement then go for it. if you think it's easier to use a select statement then go for it.

for looping statements, on using "for each" or "while" has a significant difference,

If you know how many times you needed to loop the statement, then use a for each loop statement. If you want to loop until a certain condition was met then use a while looping statement.



This post has been edited by liyam: 16 Apr, 2009 - 10:55 PM
User is offlineProfile CardPM
+Quote Post

confusedbycode

RE: How To Know When To Use Which Statement

17 Apr, 2009 - 03:18 PM
Post #4

New D.I.C Head
*

Joined: 16 Apr, 2009
Posts: 6

Thank you all for you help. Your explained it in so much easier to understand terms then what I have been getting from my instructor (figure it out for your self).
Thanks again,
User is offlineProfile CardPM
+Quote Post

sudoNut

RE: How To Know When To Use Which Statement

19 Apr, 2009 - 06:50 AM
Post #5

New D.I.C Head
*

Joined: 19 Apr, 2009
Posts: 21



Thanked: 2 times
My Contributions
As Core was saying it depends what you are doing.

Think as code as an extension of natural language. Say I want to continue eating until full this could be expressed by:

CODE
while(!full){ eatMore() }


Or say I have multiple choices of food

CODE

switch(foodType) {
                      
   case "banana": peel();
                          eat();
                          break();

   case "apple": wash()
                       eat();
                       break();

   default: eat();
               break();

}


These are rather crude examples but you get the picture. Have a look at some Java control examples at http://math.hws.edu/javanotes/c3/s3.html

BTW your instructor is not doing his job by the sounds of it! Complain if he continues to fob you off like that

This post has been edited by sudoNut: 19 Apr, 2009 - 06:51 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/26/09 09:30AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month