Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Q: swith-case in pseudocode??

Options
  • 10-11-2004 5:15pm
    #1
    Closed Accounts Posts: 5


    Can anyone tell me how to describe swith-case in pseudocode?

    Many thanks.


Comments

  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    ???

    Don't you mean Switch case? If you know what switch case does just write pseudo code which will explain what you want. Which part are you having trouble with?


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    I think he's having problems with the part that says "Assignment 1" :confused:


  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    without really knowing what you are trying to say its hard to help, so try give more info.
    but I presume it will be the same as if you were describing a bunch of if/else statements and then describe what each case can be...


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html explains the concept quite well, has some coding tips and source code.


  • Registered Users Posts: 1,865 ✭✭✭Syth


    I don't really see what the problem is. Pseudo code is a piece of piss. You basically just make up the syntax as you go along. There is no formal definition of pseudo code.


  • Advertisement
  • Registered Users Posts: 191 ✭✭Trine


    There's no strict conventions to writing pseudocode. When you're writing a note to yourself you don't bother making sure the grammar is perfect, and it's the same with pseudocode, it's shorthand programming. So a simple switch statement might look like:

    ...
    switch (var1)
    {
    case 1:
    print "Option 1"
    break

    case 2:
    print "Option 2"
    break

    default :
    print "Invalid"
    break

    }
    ...

    So just leave out any obvious programming notation like ';' and the full printf command. You could probably leave out the breaks aswell.

    You're FT228/1 right? Ride on.


  • Closed Accounts Posts: 583 ✭✭✭monkey tennis


    Werl, it wouldn't be a bad idea to get into the habit of making even pseudocode fairly complete - there's bugger all time saved by leaving out semicolons and the like for e.g. I tend to think of pseudocode as a block of regular, fully formatted (or whatever word you'd use) code, only without the rest of the program, the headers, etc etc. I'd definitely type out that above switch example with full printf statements, semicolons, braces, etc. To each their own, I suppose.

    Anyway, for any seasoned programmer, writing code like that is second nature anyway, even pseudocode :)


  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    Werl, it wouldn't be a bad idea to get into the habit of making even pseudocode fairly complete - there's bugger all time saved by leaving out semicolons and the like for e.g. I tend to think of pseudocode as a block of regular, fully formatted (or whatever word you'd use) code, only without the rest of the program, the headers, etc etc. I'd definitely type out that above switch example with full printf statements, semicolons, braces, etc. To each their own, I suppose.

    Anyway, for any seasoned programmer, writing code like that is second nature anyway, even pseudocode :)
    my pseudo code is usually some scrawl on a handy scrap of paper

    get the list
    iterate through it
    check for special value
    return list.


Advertisement