Short Answer:
6. a loop that never hits a max value or that never turns true is infinite
While (number >=0) Console.ReadLine(“Enter a positive number”) number = Console.ReadLine()
End While
7. A count-controlled loop
8. You need to initialize so you don’t fall into an infinite loop.
9. You can let user control the number of times it executes
10.
Algorithm Workbench:
#3:
For counter = 0 Step 1000 Console.WriteLine(“Value ” & counter) counter = counter + 10
#4:
Dim sum as integer = 0
Dim number as integer = 0
Dim counter as integer = 0
While counter < 10 Console.writeline(“enter a number”) Number = Console.Readline() Sum = sum + number Counter = counter + 1
End While
#9:
Dim count as integer = 0
For count = 0 Step 50 Console.writeline(“the count is ” & count) count = count + 1
End For
#10:
Dim count as integer = 1
While count < 50 Console.writeline(“The count is ” & count) count = count + 1
End While
Programming Exercises:
#7:
Module Module1
Sub Main() 'declare variables Dim year As Integer = 1 Dim numYears As Integer = 0 Dim month As Integer = 1 Dim rainfall As Double = 0.0 Dim totalRain As Double = 0.0 Dim totalMonths As Integer = 0 Dim avg As Double = 0.0
Console.WriteLine("Enter number of years for rainfall average") numYears = Console.ReadLine() While year <= numYears While month <= 12 Console.WriteLine("For year " & year & " and month " & month & " enter rainfall amount in inches") rainfall = Console.ReadLine() totalRain = totalRain + rainfall month = month + 1 End While month = 1 year = year + 1 End While totalMonths = numYears * 12 avg = totalRain / totalMonths
Console.WriteLine("The total number of months is " & totalMonths) Console.WriteLine("The total rainfall is " & totalRain & "