CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2014
    Posts
    1

    math or if statement

    Hello,

    I at some point in my past was advised that sometimes using math to determine a thing was better than the actually logic, because the processing was shorter.

    I don't remember what it was referring to, for, or if, or some sort of high-level shorthand

    However, since then, I've been using math or mod instead of if's from time to time,

    is that actually faster?
    will the average future coder understand my use of mod?


    eg, is it better to say:

    for i from 0 to 10
    whatever = i mod 5


    or

    for i from 0 to 10
    if i < 5
    whatever = i
    else
    whatever = i - 5

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: math or if statement

    If you use something that you feel that others won't find clear, add a comment.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: math or if statement

    Neither one. They don't compile without End If.

    Also, you don't use 'whatever'
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured