79
spyke
5y

can anyone confirm if this works?

Comments
  • 3
    Works in JS
    Works in php
    Probably works in a lot of langauges as EOL isn't bound by logical operators
  • 1
    Yes, tested with https://try.dot.net
    if (1==1)
    {
    // empty
    }
    else;

    Runs.
  • 0
    @rEaL-jOkEr Ah.. new account I see
  • 6
    Yes, this will probably run in most languages. It's the same thing as

    while(condition);

    A very common way of clearing a buffer is to do

    while(buffer.read());

    When the buffer is empty, it will return null, and the loop will end.

    This is allowed because it (like most other control structures) looks for a single block of code after it's declared. That's why you can omit brackets when you only need a single statement after an if.

    The brackets act as a single statement: a scope statement. You increase the depth of the scope and put code in it.

    A blank statement is still a statement. So just ending the line with a semicolon should be allowed by most control structures in most languages
  • 0
    @bkwilliams what about

    if (1 != 1)?

    Does this run, too?
  • 0
    It will work.
  • 3
    This is not threat. You are basically telling the compiler, if you don't execute that 'if', there is nothing else I can do.
    That's more like pleading
  • 0
  • 2
    @AlgoRythm I don’t know why I never understood why the input buffer would clear when throwing it in an if statement before. I always had the issue of clearing it until I read online that you could do that.
    If(std::cin >> input)

    Thanks for pointing out the obvious.....it was fucking scope all along lmao. Why didn’t I think of that? *smacks forehead*
  • 0
    It looks like quite a good code signature to use
  • 0
    I'm pretty sure compiler will ignore this (at least at C++)

    Nowadays compilers are pretty smart and they will ignore useless code, and try to optimize other code
Add Comment