adsense


Saturday, 7 November 2015

VB SCRIPT LOOP CONTROL STATEMENTS PAGE 19

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button




VB SCRIPT LOOP CONTROL STATEMENTS




Loop Control Statements 

Loop control statements change execution from its normal sequence. When execution leaves a scope, all the remaining statements in the loop are NOT executed. VBScript supports the following control statements. Click the following links to check their detail. 


Control Statement 	Description 
Exit For statement 	Terminates the For loop statement and transfers execution 
                        to the statement immediately following the loop 
Exit Do statement 	Terminates the Do While statement and transfers execution 
                        to the statement immediately following the loop 
Exit For statement      A Exit For Statement is used when we want to Exit the For 
                        Loop based on certain criteria. When Exit For is executed, 
                        the control jumps to next statement immediately after the For Loop. 


Example 
The following example uses Exit For. If the value of the Counter reaches 4, the For Loop is Exited and control jumps to the next statement immediately after the For Loop. 
<!DOCTYPE html> 
<html> 
<body> 
<script language="vbscript" type="text/vbscript"> 
 
  Dim a : a=10 
  For i=0 to a Step 2 'i is the counter variable and it is incremented by 2 
    document.write("The value is i is : " & i) 
    document.write("<br></br>") 
 If i=4 Then 
   i=i*10  'This is executed only if i=4 
   document.write("The value is i is : " & i) 
   Exit For 'Exited when i=4 
 End If   
  Next 
</script> 
</body> 
</html> 
When the above code is executed, it prints the following output on the console. 
The value is i is : 0 
 
The value is i is : 2 
 
The value is i is : 4 
 
The value is i is : 40  

 



No comments: