PDA

View Full Version : What is the value of iSum after running the following code?


kourtnee86
Dec 12, 2009, 02:39 PM
iSum = 0
For iCnt = 1 to 5
iSum = iSum + iCnt
If iCnt = 5 then iSum = 200

Perito
Dec 13, 2009, 05:49 AM
First, you need a Next statement.

Sum = 0
For iCnt = 1 to 5
iSum = iSum + iCnt
Next iCnt
If iCnt = 5 then iSum = 200

iCnt is incremented at the end of each loop (that's when the comparison is made that ends the loop), so when the FOR loop ends, the value of iCnt will be 6.

iSum will be 15 (1 + 2 + 3 + 4 + 5)