LoslegenKostenlos loslegen

If this, Else If that, Else that other thing

To add even more logic, you can follow the pattern of if, else if, else. You can add as many else if's as you need for your control logic.

if(condition1) {
    code if condition1 is true
} else if(condition2) {
    code if condition2 is true
} else {
    code if both are false
}

Diese Übung ist Teil des Kurses

Intermediate R for Finance

Kurs anzeigen

Anleitung zur Übung

  • Extend the last example by filling in the blanks to complete the following logic:
    • if micr is less than 55, print "Buy!"
    • else if greater than or equal to 55 and micr is less than 75, print "Do nothing!"
    • else print "Sell!"

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

micr <- 105.67

# Fill in the blanks
if( micr < 55 ) {
    print("Buy!")
} else if( ___ ){
    print("Do nothing!")
} ___ { 
    ___
}
Code bearbeiten und ausführen