--2-Loops

#1-While loop

​While loop videoarrow-up-right​

#100 "Cevi ist Cevi"
cevi=1

while(cevi<=100){
  
  print(paste("cevi ist",cevi))
  cevi=cevi+1
}

#2-Write a while loop

#Code a while loop with the following characteristics:
#The condition of the while loop should check if 
#speed is higher than 30.
#Inside the body of the while loop, print out "Slow down!".
#Inside the body of the while loop, decrease the speed 
#by 7 units.
#This step is crucial; otherwise your while loop will 
#never stop.

# Initialize the speed variable
speed <- 64
# Code the while loop
while ( speed>30) {
  
  print("Slow down!")
  speed<-speed-7
}
# Print out the speed variable
speed

#3-Throw in more conditionals

#4-Stop the while loop: break

#5-Build a while loop from scratch

#6-For loop

​For loop videoarrow-up-right ​

#7-Loop over a vector

#8-Loop over a list

#9-Loop over a matrix

#10-Mix it up with control flow

#11-Next, you break it

#12-Build a for loop from scratch

Last updated