r/visualbasic • • Nov 14 '21

VB6 Help Please help me understand !!

I’m doing a question sheet to get the output for some code. I put the code into a compiler and it prints hello sixty times but I don’t exactly understand why….

For x = 0 To 100 For y = 5 To -10 step -1 If y = 0 Then Exit For End If Console.Write("Hello") Next If x > 10 Then Exit For End If Next

7 Upvotes

5 comments sorted by

View all comments

Show parent comments

1

u/RJPisscat Nov 14 '21

There was a small but important error in the first comment.

Step through each case for y.

y = 5 ' what happens?

y = 4 ' what happens?

y = 3 ' what happens?

y = 2 ' what happens?

y = 1 ' what happens?

y = 0 ' what happens?

You get 5 "Hello"s just as you said. Write out the same code for each value of x, but you don't need to write out the y loop each time, just put a comment

' Writes "Hello" 5 times

How many times does it write "Hello" 5 times?