for…next : nested loop x= 0 for i = 0 to 4 for j = 0 to i-1 x=x+(i+j-1) next j next i how many...
TRANSCRIPT
For…Next : Nested Loop
X= 0For i = 0 To 4
For j = 0 To i-1X=X+(i+j-1)
Next jNext i
How many times the inner loop is executed?
What is x at the end of this loop?
Nested For…Next : Executioni=0j=0-1
i=1j=00
i=2j=01
i=3j=02
i=4j=03
No. of times inner loop is executed
0 1 2 3 4
x 0 0 13
5812
15192430
For…Next : Exit
X= 0For i = 0 To 4
For j = 0 To i-1
If x > 5 ThenExit For
End Ifx=x+(i+j-1)
Next jNext I
Exit from the inner loop
Do…Loop
Do While logical expression
Executable statement(s)Loop
Do
Executable statement(s)Loop Until logical expression
Do While…Loop
Expression
Statement(s)True
False
Do…Loop Until…
Statement(s)
Expression
True
False
Do Loops
Sum = 0Kount = 0
Do While Kount <= 10Sum = Sum + KountKount = Kount + 1
Loop
Sum = 55
Kount = 11
Sum = 0Kount = 0
DoSum = Sum + KountKount = Kount + 1
Loop Until Kount > 10
Sum = 55
Kount = 11
Decimal to Binary : Do While
Private Sub Command1_Click()Dim Deci As IntegerDim R As Byte, Bin As String
Deci = Text1.TextBin = ""Picture1.Cls
If Deci = 0 Then Bin = Str(Deci)End If
Do While Deci > 0 R = Deci Mod 2 Bin = Str(R) + Bin Deci = Deci \ 2Loop
Picture1.Print Bin
End Sub
Decimal To Binary: Do…Until
Private Sub Command3_Click()Dim Deci As IntegerDim R As Byte, Bin As String
Deci = Text1.TextBin = ""Picture1.Cls
Do R = Deci Mod 2 Bin = Str(R) + Bin Deci = Deci \ 2Loop Until Deci = 0
Picture1.Print BinEnd Sub
File Handling
Files are used for large data input/output
Create a .txt file called CarData by using Notepad (or ASCII file using other software) with following contents
“Suzuki”, 3, 4
“Toyota”, 5, 7
“Honda”, 4, 15
File Handling
Files must be Opened before any read/write operation.
Files must be Closed after any read/write operation
SyntaxOpen “CarData” For Input As #138
Opens a file called CarData.txt for read-only and this file will be called #138
The file reference number can be from 1 to 255