Hi all...i'm new here n would really gratefull for any guides.for the above question..please help me. :)
//sorry i forgot the greetings~how rude of me.
yes of course..but somehow the code doesnt work.do u know how to break the loop from inside the ~else if{}.bcause i dont intend to solve the program here.just want to know the way for the break statement to work like i want.
for(int j=10;j<b;j--)
Are you sure about the j<b part?
If j starts at 10 and is decremented it's going to stay <b until the value of j wraps back round to a positive number.
that solve a problem...then,makes me curious..the compiler doesnt detect that??!!haha..
thanx alot...but my real question doesnt solve yet.i'm looking forward for any suggestion.
#include <iostream>
usingnamespace std;
int main ()
{
constint ar_size = 10;
int int_ar[ar_size] = {1,2,3,4,5,6,7,8,9};
int a = 6;
for(int i = 0; i < ar_size; ++i)
{
if(int_ar[i] > a)
{
int_ar[i] = int_ar[i+1];
}
elseif (int_ar[i] < a)
{
a = int_ar[i+1];
break;
}
}
std::cout << a << std::endl;
}
As you can see the loop does break from there but only if the execution path can get there, so are you sure that it is possible for arry[j] < a to be true?
I can't answer for your particular case but lets say a is -1 and all values in the array are positive, then no value in the array will ever be less than a so it will never be true and never get to break.
i got problem to transfer the target into a temporary variable n get it into where it should belong.
n i thinnk this is because of the break statement.am i wrong?
hmm...i see that now.thanx again mooce however why 'a' couldnt store any value from the array. arry[i+1]= a;//copy target into a temp
i purposely do this to store value in 'a'.