Copy and paste the following code to your R Studio platform or R version:

# The While & For Loop

while(TRUE) {

print(“Hello James! How are you?”)
# press escape on the keyboard
# to cancel this infinite loop
}

counter <- 1
while(counter < 12) {

print(counter)
counter <- counter + 1

}
counter

# the for loop may be more convenient from time to time

for(i in 1:5) {

print(“Hello James! Having fun with R?”)

}
1:5 # to understand the concept of vectors that R utilises

counter <- 1
for(counter in 1:5) {

print(“Hello James! Having fun with R?”)

}
counter

Posted by Dimitris

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s