Quote:
Originally posted by harrylee2003
int cerrent = 5;
int used = 29;
for(cerrent; cerrent<used; i++)
{
int tem;
tem= data[used];
data[used +1] = tem;
used - 1;
}
data[cerrent] = newnumber;
i try the way above ....but it didn't work...
|
I could not clearly understand what you were trying to do but I would like to point out a few things :
1) The above for loop is basically an infinite loop
2) The general sysntax of a for loop is
Code:
for(initialization expression ; test expression ; update expression)
{
body of the loop
}
3) Any or all of the expressions might be skipped, and multiple expressions seperated by commas are also allowed.
So lets analyse your for loop
1) The initialisation expression is just cerrent which actually does not mean anything because it does not initialise current to any value. It's as good as left out.
2) The test condition says that the loop should run as long as cerrent < used but nowhere in the loop are cerrect or used modified. Since the initial values of these variables satisfy the test condition the above construct is basically an infinite loop.
3) The update condition i++ is meaningless an nowhere in the loop is i being used.
4) The statement used - 1 does not do anything. It is just an expression that has a value of used - 1. That is to say the statement does not change the value of used.
Maybe you intended doing something like :
Code:
used-- or,
used = used -1 or maybe,
used = used -i
Please be more clear in what your actual problem is. I would recommend you to first gain a thorough understanding of some basic constructs like for, do-while, while and then try them out.
Also, use code tags
when posting in code.
Hope this helps!