Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my Visual Basic and I’m trying to learn how to print in reverse order .

Dim data() = {30, 50, 60, 35, 43, 13, 81, 29, 74, 21}
Dim i = 0

While (i < 9)
Console.WriteLine(data(i))
i = i + 1
End While

What I have tried:

I don’t know how to do it in the array I’m
Not sure how to get it in the while loop. I tried it for loop but while loop is different.
Posted
Updated 29-Oct-19 12:20pm
Comments
ZurdoDev 29-Oct-19 17:17pm    
Reverse the loop instead of going 0 to 9, go 9 to 0.
Mohibur Rashid 29-Oct-19 17:20pm    
what's your method?

Start with the last element, and reduce your index instead of increasing it. If you use the Array.Length property, and subtract one you have the index of the final element: in your case that would be 10 - 1 = 9

I'd use a For loop instead of While though.
 
Share this answer
 
Advice:
- play values in this code and see what results it gives.
- use the debugger to watch exactly what the code is doing.
- try to figure out what changes are needed to print list in reverse order.
- find tutorials about loops in basic.
and experiment.

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

Visual Basic / Visual Studio Video Tutorial - Basic Debugging - YouTube[^]
Visual Basic .NET programming for Beginners - Breakpoints and Debugging Tools[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900