Results 1 to 3 of 3

Thread: Best way

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    England
    Posts
    94

    Best way

    Hey Guys

    I was wondering what would be the best way of doing something in you opinion

    i want to carry out code if depending on the value of two variables so i don't knwo wether nested case statements or 2 stament if staments would be better.


    so i would have

    switch(I)
    {
    case 0:
    {
    switch (d)

    etc

    or

    if ((d == 0) && (i = 0))


    i am currently doing it with ifs but is thsi teh best way to do it i meean which way is more efficent.


    Cheers
    Peter
    "Let's all join forces, rule with an iron hand...and prove to all the world, metal rules the land..."
    -- Judas Priest

    My email is [email protected]

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I don't think there's any difference in the generated code between a switch and a list of else ifs. However, using two switches will generate two if's, rather than a boolean operator and another if. Not sure on the clock timings for those though.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Lively Member
    Join Date
    Dec 2000
    Location
    Indiana
    Posts
    73

    Optimization

    To do an else if with a one liner statement, its better to do it in if-form because with the switch statement, you need a break; clause.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width