-
Notifications
You must be signed in to change notification settings - Fork 0
/
_004_conditions.R
35 lines (30 loc) · 906 Bytes
/
_004_conditions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Filename: _004_conditions.R
# Title: Conditional statements
# Author: Raghava | GitHub : @raghavtwenty
# Date Created: June 20, 2023 | Last Updated: May 27, 2024
# Language: R | Version: 4.4.0
# Operators in R
# & (ampersand) - AND operator
# | (pipe) - OR operator
# == Equal
# != Not equal
# > Greater than
# < Less than
# >= Greater than or equal to
# <= Less than or equal to
current_year = 2024
# Input from the user
cat("Enter the current year: ")
user_input <- readLines("stdin",1)
# Datatype conversion
user_input <- as.integer(user_input)
# If, else if, else conditions
if (current_year == user_input){
print("Matched.")
} else if (current_year < user_input){
print("Current year is lesser than the input year.")
} else if (current_year > user_input){
print("Current year is greater than the input year.")
} else {
print(paste("Input ",user_input," is invalid."))
}