Pętla while

Intermediate R

Filip Schouwenaars

DataCamp Instructor

Pętla while

while(condition) {
  expr
}
while(ctr <= 7) {
Intermediate R

Pętla while

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

Pętla while

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

Pętla while

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

Pętla while

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

Pętla while

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

Pętla while

while(condition) {
  expr
}
while(ctr <= 7) {
  print(paste("ctr is set to", ctr))
  ctr <- ctr + 1
}
  • Brak wydruku
Intermediate R

Pętla 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
Intermediate R

Pętla while

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

Nieskończona pętla while

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"
...
Intermediate R

Instrukcja 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"
Intermediate R

Czas na ćwiczenia!

Intermediate R

Preparing Video For Download...