//we will write a program to demonstrate use of break; and continue; statements.
//
//first we wil write a program for break statement. we will find the index of string at which the character is 'o' , once found it we shall return the index of the string at which 'o' was detected first.
//
#include <iostream>
#include <string>
using std::string;
int index_finder(string line)
{
int index = -1;
for (int i = 0; i < line.size(); i++)
{
if (line[i] == 'o')
{
index = i;
break;
}
}
return index;
}
string space_removal(string line2)
{
std::string new_str;
for (int i = 0; i < line2.size(); i++)
{
if (line2[i] != ' ')
{
new_str += line2[i]; // Use the += operator to append characters
}
}
return new_str;
}
int main()
{
std::string sentence = "I love coding";
std::cout << "the character 'o' was found at " << index_finder(sentence) << std::endl;
std::cout << "the string after removing the spaces is : " << space_removal(sentence) << std::endl;
return 0;
}