For...Next statement repeats a group of statements a specified number of times.
For counter = start To end [Step step]
counter: Numeric variable used as a loop counter. The variable can't be an array element or an element of a user-defined type.
start: Initial value of counter.
end: Final value of counter.
step: Amount counter is changed each time through the loop. If not specified, step defaults to one.
statements: One or more statements between For and Next that are executed the specified number of times.
'For...Next Counter = 1 For Counter = 1 to 4 Total =Inputbox("Please enter the total marks in numbers") If Total < 50 Then MsgBox "Fail" ElseIf Total >=50 and Total <=60 then Msgbox "Second Class" ElseIf Total >60 and Total <80 then Msgbox "First Class" ElseIf Total >=80 then Msgbox "Distinction" Else Msgbox "Invalid Marks" End If Next
' increment loop by 3 Counter = 1 Result = 0 For Counter = 1 to 10 step 3 Result=Result + Counter Print Result Next
'Decrement loop by 2 For Counter = 10 to 1 step -2 Print Counter Next
'Exit For Loop For Counter=1 to 10 If Counter=6 Then Exit for End If Print Counter Next