Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Sum Threshold | R Loops Tutorial
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Control Flow in R

bookChallenge: Sum Threshold

Oppgave

Swipe to start coding

Write code that uses a while loop to sum all even numbers from the vector nums until the sum exceeds 50. Store the result in a variable named even_sum.

  • Start with the vector: nums <- c(8, 3, 12, 5, 10, 7, 14, 2).
  • Initialize the sum and a loop index variable.
  • In each iteration, check if the current number is even and, if so, add it to your sum.
  • Stop the loop as soon as the running sum becomes greater than 50.
  • Store the final sum in a variable named even_sum.

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 4
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

close

bookChallenge: Sum Threshold

Sveip for å vise menyen

Oppgave

Swipe to start coding

Write code that uses a while loop to sum all even numbers from the vector nums until the sum exceeds 50. Store the result in a variable named even_sum.

  • Start with the vector: nums <- c(8, 3, 12, 5, 10, 7, 14, 2).
  • Initialize the sum and a loop index variable.
  • In each iteration, check if the current number is even and, if so, add it to your sum.
  • Stop the loop as soon as the running sum becomes greater than 50.
  • Store the final sum in a variable named even_sum.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 4
single

single

some-alt