Print Array Values using While Loop in C++


The program first initializes the array arr with the values {11, 22, 33, 44, 55} using an array initializer. It then sets an integer variable n to 0 and enters a while loop. The while loop checks if n is less than or equal to 4 (which is the index of the last element in the array). If this condition is true, the loop prints the value of arr[n] on a new line using cout and then increments n by 1. The loop continues until n becomes 5, at which point the loop condition is false and the program exits.

Source Code

#include <iostream>
using namespace std;
int main()
{
  int arr[]={11, 22, 33, 44, 55};
  int n=0;
  while(n<=4)
  {
    cout<<arr[n]<<endl;
    n++;
  }
  return 0;
}
To download raw file Click Here

Output

11
22
33
44
55

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples