Professional Documents
Culture Documents
While Loops PDF
While Loops PDF
1/10
2/10
WE WILL LOOK AT
while
do ... while
3/10
LOOPS
A loop repeats some code again and again
Here we will look at:
while
do ... while
4/10
WHILE LOOPS
A while loop is the simplest loop
while(condition){
INDEXOF()
string.indexOf("text")
gives you the location of the first "text" in the string
For example:
vartext="Thecat'shatwaswet"
result=text.indexOf("at")
result will be 5
6/10
<!doctypehtml>
<html><head>
<title>Exampleofwhile()</title>
<script>
varresponse,finished
finished=false
alert("Rossiterisagreatname.")
while(!finished){
response=prompt("Doyouagree?")
if(response.indexOf("y")==0)
finished=true
}
</script>
</head></html>
7/10
8/10
9/10
<!doctypehtml>
<html><head>
<title>Exampleofdo..while()</title>
<script>
varresponse,finished
finished=false
alert("Rossiterisagreatname.")
do{
response=prompt("Doyouagree?")
if(response.indexOf("y")==0)
finished=true
}while(!finished)
</script>
</head></html>
10/10