r/visualbasic • • Feb 01 '16

[VB2015] User Input Loop question

Hello I am working on an visual basic assignment. For what its worth I got it to work/filled the requirements for it but I want to try to get it to work in a loop. So I did a do while loop. And that works as well...but can't exit out of the loop leading me into a infinite loop. Is there anyway for me to exit out properly?

Code pasted here: http://paste.ofcode.org/6Qn5ViBt33442Fwum2CRyZ

6 Upvotes

3 comments sorted by

View all comments

2

u/Air_chandler Feb 01 '16 edited Feb 01 '16

Surely here you want to declare the input inside the Do loop then have if statements say if input = "a" do sound then elseif input = "something else" do something else, and have elseif input = "exit" to exit the loop as you wanted (use exit do in this case), because looking at this your logic is unclear to me.

For example:

Do

dim input as Char

Console.writeline("Enter a letter to hear a sound, enter E to exit")

input = console.readline()

If input = "x" do sound

elseif input = "other x" do another sound

elseif input = "E" exit do

else console.writeline("wrong input")

loop

In this example the user will be asked to input a letter to play corresponding sound which then input takes this value, and will keep being asked until they enter E to exit the loop.