Module Module1 Sub Main() Console.WriteLine("Normal For Loop") For num1 = 1 To 30 Console.WriteLine(num1) Next Console.WriteLine() Console.WriteLine("For Loop that exits before it's finished") For num1 = 1 To 30 Step 4 Console.WriteLine(num1) If num1 >= 23 Then Exit For End If Next Console.ReadLine() End Sub End Module can anyone explain this.pls hurry
I dont know the programming language which you write this by. but I can explain it to you : we have 2 For Loops the first one is a normal one,mean that the program will enter all the 30 loop and it will write the counter "num1" every loop (num1 will increase from 1 to 30) the second for loop is not normal, means that the program execution will not do the all loops , and it will exit from the loop when the condition num1 >= 23 will be write
the output of the program is : Normal For Loop 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 For Loop that exits before it's finished 1 5 9 13 17 21
but when did the program the output was Normal For Loop 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 For Loop that exits before it's finished 1 5 9 13 17 21 25 that's the reason i am confused
ya ya thats right , I made I small mistake :) the " Console.WriteLine(num1)" comes before the " If num1 >= 23 Then" thats mean the program will write num1 before checking the condition so when num1=21 the program will write it this will check the condition and see that its true , then num1 will become 25 and the program will write it before checking if it bigger than 23 or not
thanks man
Join our real-time social learning platform and learn together with your friends!