Module Module1
Sub Main()
'declare variables
Dim s1 As String = Console.ReadLine()
Dim a As Integer = 0
Dim b As Integer = 0
Dim c As Integer = 0
Dim d As Integer = 0
Dim e As Integer = 0
'loop
Do
Console.WriteLine("Please enter a sentence")
s1 = Console.ReadLine()
If s1 = "all done" Then Exit Do ' exit loop if s1 = "all done"
For count As Integer = 0 To s1.Length - 1
'count occurences of letters
Select Case s1.Chars(count)
Case ("a"c)
a += 1
Case ("b"c)
b += 1
Case ("c"c)
c += 1
Case ("d"c)
d += 1
Case ("e"c)
e += 1
End Select
Next
'output results
Console.WriteLine("A = " & a & vbNewLine & "B = " & b & vbNewLine & "C = " & c & vbNewLine & "D = " & d & vbNewLine & "E = " & e)
Loop
'this should be in a loop like the letter counter loop
'prompt for a sentence
Console.WriteLine("Please enter something")
Dim s3 As String = Console.ReadLine()
'replace words in sentence
Dim s2 As String = s3.Replace("hi", "hello").Replace("today", "tomorrow").Replace("hate", "love")
'output results
Console.WriteLine(s3)
Console.WriteLine(s2)
Console.ReadLine()
End Sub
End Module
4 Replies - 629 Views - Last Post: 10 April 2011 - 11:48 AM
#1
Help how do I reset a loop so the when it loops it goes back to 0
Posted 08 April 2011 - 05:27 PM
In the first loop once it cycles through once it does not reset the data so it continues to hold the previous data so therefore the outcome is incorrect. Can I reset it to start back at 0 ???
Replies To: Help how do I reset a loop so the when it loops it goes back to 0
#2
Re: Help how do I reset a loop so the when it loops it goes back to 0
Posted 08 April 2011 - 05:35 PM
Have you considered setting back to zero?
Where in the loop would be the best place to do that?
Where in the loop would be the best place to do that?
#3
Re: Help how do I reset a loop so the when it loops it goes back to 0
Posted 10 April 2011 - 08:40 AM
I am assuming at the end of the loop, this is where I struggle most with these loops I just don't understand how to get it back to the original once it has gone through the data once. I struggle with how I write it.
AdamSpeight2008, on 08 April 2011 - 05:35 PM, said:
Have you considered setting back to zero?
Where in the loop would be the best place to do that?
Where in the loop would be the best place to do that?
#4
Re: Help how do I reset a loop so the when it loops it goes back to 0
Posted 10 April 2011 - 09:56 AM
Wherever you want to reset it to zero just pop this in:
Count is the variable the for loop is using to count so you just have to set that variable to 0.
count = 0
Count is the variable the for loop is using to count so you just have to set that variable to 0.
#5
Re: Help how do I reset a loop so the when it loops it goes back to 0
Posted 10 April 2011 - 11:48 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|