For loops in computer programs are used to perform repetitive operations, while if conditions are used to make decisions
The program in C++, where comments are used to explain each line is as follows:
#include <iostream>
using namespace std;
int main(){
//This initializes the array
char name1[] = {'R','O','Y','A','L'};
//This declares a character variable
char searchedChar;
//This gets input for the character
cin>>searchedChar;
//This iterates through the array
for(int i = 0; i<5;i++){
//If the searched character equals the current array element
if (searchedChar == name1[i]){
//This prints the index of the element
cout<<i;
}
}
return 0;
}
Read more about loops and conditions at:
https://brainly.com/question/18750495