Useful alternative control structures?

后端 未结 28 921
礼貌的吻别
礼貌的吻别 2021-01-30 02:20

Sometimes when I am programming, I find that some particular control structure would be very useful to me, but is not directly available in my programming language. I think my

28条回答
  •  礼貌的吻别
    2021-01-30 03:01

    This is just a general idea and syntax:

    if (cond)
       //do something
    else (cond)
       //do something
    also (cond)
       //do something
    else
       //do something
    end
    

    ALSO condition is always evaluated. ELSE works as usual.

    It works for case too. Probably it is a good way to eliminate break statement:

    case (exp)
       also (const)
          //do something
       else (const)
          //do something
       also (const)
          //do something
       else
          //do something
    end
    

    can be read as:

    switch (exp)
       case (const)
          //do something
       case (const)
          //do something
          break
       case (const)
          //do something
       default
          //do something
    end
    

    I don't know if this is useful or simple to read but it's an example.

提交回复
热议问题