Loop while

R intermediário

Filip Schouwenaars

DataCamp Instructor

Loop while

while(condition) {
  expr
}
while(ctr <= 7) {
R intermediário

Loop while

while(condition) {
  expr
}
while(ctr <= 7) {
  print(paste("ctr is set to", ctr))
R intermediário

Loop while

while(condition) {
  expr
}
while(ctr <= 7) {
  print(paste("ctr is set to", ctr))
  ctr <- ctr + 1
}
R intermediário

Loop while

while(condition) {
  expr
}
while(ctr <= 7) {
  print(paste("ctr is set to", ctr))
  ctr <- ctr + 1
}
"ctr is set to 1"
R intermediário

Loop while

while(condition) {
  expr
}
while(ctr <= 7) {
  print(paste("ctr is set to", ctr))
  ctr <- ctr + 1
}
"ctr is set to 2"
R intermediário

Loop while

while(condition) {
  expr
}
while(ctr <= 7) {
  print(paste("ctr is set to", ctr))
  ctr <- ctr + 1
}
"ctr is set to 7"
R intermediário

Loop while

while(condition) {
  expr
}
while(ctr <= 7) {
  print(paste("ctr is set to", ctr))
  ctr <- ctr + 1
}
  • Sem impressão
R intermediário

Loop while

ctr <- 1
while(ctr <= 7) {
  print(paste("ctr is set to", ctr))
  ctr <- ctr + 1
}
"ctr is set to 1"
"ctr is set to 2"
...
"ctr is set to 7"
ctr
8
R intermediário

Loop while

ctr <- 1
while(ctr <= 7) {
  print(paste("ctr is set to", ctr))
  ctr <- ctr + 1
}
R intermediário

Loop while infinito

ctr <- 1
while(ctr <= 7) {
  print(paste("ctr is set to", ctr))

}
"ctr is set to 1"
"ctr is set to 1"
"ctr is set to 1"
"ctr is set to 1"
"ctr is set to 1"
"ctr is set to 1"
"ctr is set to 1"
...
R intermediário

Instrução break

ctr <- 1
while(ctr <= 7) {
  if(ctr %% 5 == 0) {
    break
  }
  print(paste("ctr is set to", ctr))
  ctr <- ctr + 1
}
"ctr is set to 1"
"ctr is set to 2"
"ctr is set to 3"
"ctr is set to 4"
R intermediário

Vamos praticar!

R intermediário

Preparing Video For Download...