I have wrote the code to process the elements by reading from the txt file. I tried to swap values... but is's not working. Pls help me out.
begin
$display("rdata");
for (i=0; i<5; i=i+1)
for (j=i+1; j<6; j=j+1)
if(data[i]<data[j])
k=data[i];
data[i]=data[j];
data[j]=k;
$display("%h",data[i]);
fp1=$fopen("vectors2.txt");
Select the scope of if condition. Try this:
$display("rdata");
for (i=0; i<5; i=i+1)
for (j=i+1; j<6; j=j+1)
if(data[i]<data[j])
{
k=data[i];
data[i]=data[j];
data[j]=k;
}
$display("%h",data[i]);
fp1=$fopen("vectors2.txt");
Related
Hi I have EA with code structure like this,
void OnTick()
{
resetCounterVar(); //there's for loop
CloseOrders(); //there's for loop
UpdateAllOpenOrders(); //there's for loop
SetSLTP(); //there's for loop
CheckPendOrder(); //there's for loop
if(IsNewCandle() && pendingOrderCount<MaxPendingOrder)
OpenOrders();
}
I want to make the for loop instead for every function into like this,
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
if(OrderSelect(i,SELECT_BY_POS) &&
OrderSymbol() == Symbol()
{
resetCounterVar();
CloseOrders();
UpdateAllOpenOrders();
SetSLTP();
CheckPendOrder();
if(IsNewCandle() && pendingOrderCount<MaxPendingOrder)
OpenOrders();
What I want to ask does the second code structure more efficient then the first one?
I'm working with processing 2.2.1, and I am 90% sure that this is syntactically correct. I keep getting an error explaining that it is incorrect with an "unexpected token: int".
void growEllipse(int ellipseHW){
if(int i = 0; i != width*2; i++){
ellipseHW = ellipseHW++;
}
I have tried moving the int to within the function, like so (check below) but then I get an error saying that it is "expecting RPAREN, found ';'".
void growEllipse(int ellipseHW){
int i;
if(i = 0; i != width*2; i++){
ellipseHW = ellipseHW++;
}
}
This is rather frustrating because it seems syntactically correct.
Can anybody help me figure it out?
It looks like you're trying to use a for loop, not an if statement:
for(int i = 0; i != width*2; i++){
ellipseHW = ellipseHW++;
}
More info on the for loop can be found in the Processing reference.
Try using a 'for' statement instead of an 'if' statement.
I have an ini file with information like:
slExpsave_0 = 0.23;
slExpsave_1 = 0.40;
slExpsave_2 = -0.85;
...
I need to use them in a loop;
...
for(var i=0; i<3; i++)
{
slExpArray[i].value = slExpsave_[i];
}
But it doesn't work.
What is the reason for this?
I'm guessing this is Javascript, so you should use an array if you want to access them within a loop:
slExpsave_ = [0.23, 0.40, -0.85];
Does this help?
Let me explain my problem more clearly.
As I did it manually, It worked as I wanted:
slExpsave_0 = 0.23;
slExpsave_1 = 0.40;
slExpsave_2 = -0.85;
slExpArray[0].value = slExpsave_0; // output is 0.23;
slExpArray[1].value = slExpsave_1; // output is 0.40;
slExpArray[2].value = slExpsave_2; // output is -0.85;
when I tried to do it automatically by put in the for loop:
the first one I tried:
for(var i=0; i<3; i++)
{
slExpArray[i].value = "slExpsave_" + i;
}
// output is slExpsave_0, slExpsave_1, slExpsave_2
the second was:
for(var i=0; i<3; i++)
{
slExpArray[i].value = slExpsave_[i];
}
// doesn't work.
Is there a halfway elegant way to upgrade to following code snipped by the use of boost's scoped_ptr or scoped_array?
MyClass** dataPtr = NULL;
dataPtr = new MyClass*[num];
memset(dataPtr, 0, sizeof(MyClass*));
allocateData(dataPtr); // allocates objects under all the pointers
// have fun with the data objects
// now I'm bored and want to get rid of them
for(uint i = 0; i < num; ++i)
delete dataPtr[i];
delete[] dataPtr;
I did it the following way now:
boost::scoped_array<MyClass*> dataPtr(new MyClass*[num]);
memset(dataPtr.get(), 0, num * sizeof(MyClass*));
allocateData(dataPtr.get());
Seems to work fine.
I am brand new to coding, and I cannot for the life of me, through any amount of voodoo or googling, understand why this simple code will not work in Google Scripts:
var student = new Object; // name & student's hours
var studentNames = new Array;
for (var i=0; i <= allSheets[1].getLastRow(); i++); {
studentNames[i] = allSheets[1].getRange((i+3),1).getValue();
student[studentNames[i]] = allSheets[1].getRange(i+3, 3).getValue();
}
For some strange reason it just fills the array studentNames with "null", and the Object student will only show one key.
If I bypass the for loop like so,
studentNames[0] = allSheets[1].getRange(3,1).getValue();
studentNames[1] = allSheets[1].getRange(4,1).getValue();
studentNames[2] = allSheets[1].getRange(5,1).getValue();
studentNames[3] = allSheets[1].getRange(6,1).getValue();
everything works perfectly!
If someone could tell me what I am doing wrong I would be much obliged.
remove the semicolon at the end of your for loop
for (var i=0; i <= allSheets[1].getLastRow(); i++); <- this one
cheers : )
There is an extra semicolon on line 4:
for (var i=0; i <= allSheets[1].getLastRow(); i++); {
should be:
for (var i=0; i <= allSheets[1].getLastRow(); i++) {
The semicolon ends up closing the body of the for loop, so the block {...} ends up executing only once.