#Write a function that simulates the outcome of one play at the slot machine,

#i.e. either returns 0 or 2 with probability p and 1-p respectively.

I wrote the following code:

Slot <- function(nflips,p)

slot<-10

{

x <- runif(nflips)

ifelse(x<=p,0,2)

}

Slot(1,0.5)

# Now, if I start with $10, and decide to play until you either win $20, or lose all money. Write a `while`

loop to simulate this process. In the end you will have either $20 or $0. How many times did you play? Assuming p=0.05

I looked at different sources on the web and came up with:

{begin<-10

i<-1

while (i<=10)

{x <- runif(begin)

ifelse(x<=0.5,0,2)}

begin<-begin+1}

Since I have no coding experience, would appreciate some tips on how to use 'while' statement; especially here when we have 2 conditions i.e. either I lose $10 or win $20.

Thank you.