Count-Controlled Loops: Exercises
Count-Controlled Loops: Exercises
Count-controlled loops
1. Write a program to take as input a positive integer. The program is to output integers counting from 1 to the number input. For
example, an input of 5 will output: 1 2 3 4 5
2. Amend your program from (1) to count down from the number input to 1. For example, an input of 5 will output: 5 4 3 2 1
3. Amend your program from (1) to take as input a second integer to be used as counting interval. For example, the input of 20, 4
will output: 1 5 9 13 17
4. Write a program to take as input ten numbers and output the largest number.
5. Amend your program from (5) to output the smallest number.
6. Write a program that asks the user for an integer between 1 and 5 (inclusive). The program is to check that the input is within
the range and if not, prompt the user for a valid integer until the input is within the range.
7. Write a program to take as input two positive integers. The program is to output integers counting from the first integer to the
second integer. For example, the input 3, 7 will output: 3 4 5 6 7
Public Class frmLoopsExercises
Do
Number = InputBox("Enter Number")
Loop Until Number > 0
For i = 1 To Number
ListBox1.Items.Add(i)
Next i
End Sub
Do
nextNumber = InputBox("Please enter next Number")
Counter = Counter + 1
If nextNumber > BiggestSoFar Then
BiggestSoFar = nextNumber
End If
Loop Until Counter = 10
Do
nextNumber = InputBox("Please enter next Number")
Counter = Counter + 1
If nextNumber < smallestSoFar Then
smallestSoFar = nextNumber
End If
Loop Until Counter = 10
Do
Number = InputBox("Enter Number")
Loop Until Number >= 1 And Number <= 5
End Sub