How do I break out of an R command?

Learning PHP: Is there a way to make a one-line conditional statement when there more than one function calls and the break command?

  • When there is code like this, for ($i=1; $i<=5; $i++) { if ( $var ) { break; } } I know it can be shorten to this way: for ($i=1; $i<=5; $i++) { if ( $var ) break; } But if it is like this and has one function, for ($i=1; $i<=5; $i++) { if ( $var ) { need_to_do_something(); break; } } is there a way to make the if-block just one line?

  • Answer:

    for ($i=1; $i<=5; $i++) { if ( $var && need_to_do_something() ) break; } && is a shortcircuit condition, means the second part won't be executed if $var is false Assuming need_to_do_something() returns something that IF considers to be true, there you go

Maxim Postoronca at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.