BaşlayınÜcretsiz Başlayın

If this

If statements are great for adding extra logical flow to your code. First, let's look at the basic structure of an if statement:

if(condition) {
    code
}

The condition is anything that returns a single TRUE or FALSE. If the condition is TRUE, then the code inside gets executed. Otherwise, the code gets skipped and the program continues. Here is an example:

apple <- 54.3

if(apple < 70) {
    print("Apple is less than 70")
}
[1] "Apple is less than 70"

Relational operators are a common way to create the condition in the if statement! The variable, micr, has been created for you.

Bu egzersiz

Intermediate R for Finance

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Fill in the if statement that first tests if micr is less than 55, and if it is, then prints "Buy!".

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

micr <- 48.55

# Print "Buy!" if micr is less than 55
if( ___ ) {
    print(___)
}
Kodu Düzenle ve Çalıştır