**usually when i started coding and started learning about string array or normal array ,i used to work with string array or array by typing strlen() or size() in the for loop condition**.↵
↵
~~~~~↵
for(int i=0;i<strlen();i++)↵
{↵
statement;↵
}↵
~~~~~↵
↵
**but its a totally wrong way to set up the condition.because normally if my algorithms complexity is O(n),and i use strlen() it,my time complexity will become O(n^2).**↵
****↵
**this happens because every time for loop come to check the condition it will start checking what is the string length is,so total complexity will become n*n = n^2**↵
****↵
**so to avoid this kind of situation ,declare integer variable n= strlen(),and then put the code like this**↵
↵
↵
~~~~~↵
int n= strlen();↵
for(int i=0;i<n;i++)↵
{↵
statement;↵
}↵
~~~~~↵
↵
**i hope this will be helpful :).**
↵
~~~~~↵
for(int i=0;i<strlen();i++)↵
{↵
statement;↵
}↵
~~~~~↵
↵
**but its a totally wrong way to set up the condition.because normally if my algorithms complexity is O(n),and i use strlen() it,my time complexity will become O(n^2).**↵
****↵
**this happens because every time for loop come to check the condition it will start checking what is the string length is,so total complexity will become n*n = n^2**↵
****↵
**so to avoid this kind of situation ,declare integer variable n= strlen(),and then put the code like this**↵
↵
↵
~~~~~↵
int n= strlen();↵
for(int i=0;i<n;i++)↵
{↵
statement;↵
}↵
~~~~~↵
↵
**i hope this will be helpful :).**