Explain Counter Controlled Loop program.

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter5: The Repetition Structure
Section: Chapter Questions
Problem 3RQ
icon
Related questions
Question

Explain Counter Controlled Loop program.

Expert Solution
Step 1

Counter Controlled Loop:

  • A counter controlled loop is also called definite loop because the number of repetitions is called before the loop begins execution.
  • Count controlled loop will stop execution after running certain number of times.
  • Syntax:

                Computer Science homework question answer, step 1, image 1

  • The count is kept in variable called index or counter.
  • If the index reaches the loop bound value then the loop will terminated.
  • The following example prints the character and its ASCII value for all lower case characters.
Step 2

Program: 

//Defining the class

class Main {

  //Defining the main() function

  public static void main(String[] args) {

    //Counter control loop

    for (char x = 'a'; x <= 'z'; x++)

     //Printing statement

     System.out.println(x + " = " + (int) x);

  }

}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer