9.3k views
1 vote
Must i but End if in this visual basic. 6 program

Sub main ( )
Dim i as integer, p as integer
P = 1
For i = 1 to 100
if ( 1 mod 4 = 0 ) then
p = p*i
Next i
MsgBox " الناتج هو " & p
End sub ​

User Likeon
by
5.1k points

1 Answer

6 votes

You use end if only if the entire statement does not fit on one line.

So this format does not require end if:

If condition Then [ statements ]

And this one does:

If condition [ Then ]

[ statements ]

End If

I left out the else syntax for simplicity.

So the example program you gave will require an end if before the next i.

The expression in the if statement should be (i mod 4) rather than (1 mod 4). Typo?

User Sunjay Varma
by
5.5k points