PDA

View Full Version : for data show out of loop



Anupamp
2nd February 2017, 01:28
for(j=0;j<mylist.length();j++)
{
if(mylist[j]=="Anup")
{
es3=mylist[j-13];
arr[j]=es3.toDouble();
qdebug()<<arr[j];
}
}
i want to show the arr[j] values out of loop i am not able to do. plzz help
so that i can call arr[j] value any where

jefftee
2nd February 2017, 03:33
You don't show enough of your code to answer your question. Where is "arr" declared and what is it's scope for starters?

I also doubt this code does what you want. You are only assigning arr[j] a value when your mylist[j] is equal to "Anup". All other iterations of this loop won't assign a value to the other values that exit in the j=0 to j < mylist.length() for loop.

Anupamp
2nd February 2017, 05:13
int arr[50];
QStringlist mylist;
Qstring es3;

for(j=0;j<50;j++)
{
if(mylist[j]=="Anup")
{
es3=mylist[j-13];
arr[j]=es3.toDouble();
qdebug()<<arr[j];
}
}


data is coming in the loop but i want out of the loop.

jefftee
2nd February 2017, 05:22
What have you tried and what error(s) do you get?

For starters, you don't initialize "arr" and only assign arr[j] when mylist[j] == "Anup", so of the 50 integers in the arr integer array, only one of them would have a defined value, which can't possibly be what you want.

Try the following after the end of your loop:


int test = arr[0];
qDebug() << "test=" << test;

That code would access the first item in the integer array named "arr", but will likely be garbage or a random value because you have not initialized the items in the array. I suspect this is not your actual code, because I don't see where you define "j", but assuming it's defined in the actual for statement, then it will be out of scope (inaccessible and invisible) outside of the for loop. Is that what you're asking?

Show your actual code (using code tags) and try again to explain what it is you are trying to do, what you have tried, and what error(s) you're getting.

Anupamp
2nd February 2017, 07:24
thanks alot for the help