In Eclipse (4.4) CDT (8.5) on windows (7) the indentation of new lines within if and else if conditions does not make sense to me. Where in eclipse is this set?
I have tried looking in Window > Preferences > C/C++ > Code Style > Formatter but could not see any relevant setting.
An example where I hit the return key as I type the conditions or select the lines and press Ctrl+I ("Fix Indentation"). Note that the first four lines all have the same indentation despite differing levels of nesting. The following fifth line indents two more levels than the preceding line, as does the seventh line both with no apparent relation to the level of nesting.
else if (((wp == SMB_Protocol_Write_Byte) && (qcn >= 1)
&& (rp != SMB_Protocol_Process_Call)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Write_Word) && (qcn >=2)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Block_Write)
&& (qcn >= (CMD_Number_Bytes_max + 1)))) {
e = EXIT_FAILURE;
}
I would prefer something along the lines of the following:
else if (((wp == SMB_Protocol_Write_Byte) && (qcn >= 1)
&& (rp != SMB_Protocol_Process_Call)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Write_Word) && (qcn >=2)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Block_Write)
&& (qcn >= (CMD_Number_Bytes_max + 1)))) {
e = EXIT_FAILURE;
}
Is it possible to change this?
Also if someone could comment with an explanation of the current indentation/nesting formatting it would be appreciated!
EDIT: Realised this may be similar to Eclipse JDT Code Formatter: Indent parameter in IF-Statement
Is it possible to change this?
Yes. With the default indentation strategy (K&R built-in) I get the same as you with Ctrl+I, but if I do Ctrl+Shift+F (format code) I get the following.
} else if (((wp == SMB_Protocol_Write_Byte) && (qcn >= 1)
&& (rp != SMB_Protocol_Process_Call)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Write_Word) && (qcn >= 2)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Block_Write)
&& (qcn >= (CMD_Number_Bytes_max + 1)))) {
If you want to get column alignment, rather than simple indentation on continued lines, create your own formatting profile and change the following:
Indentation tab -> Tab policy to either Spaces only or Mixed
With the default of Tabs only the indents will be to the next tab stop
Line Wrapping tab -> Expressions/Binary Expressions set Indentation policy to Indent on column
This is what you end up with when you format (but not when you simply correct indentation):
} else if (((wp == SMB_Protocol_Write_Byte) && (qcn >= 1)
&& (rp != SMB_Protocol_Process_Call)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Write_Word) && (qcn >= 2)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Block_Write) && (qcn
>= (CMD_Number_Bytes_max + 1)))) {
Here are screenshots showing the settings:
and
Related
It seems this HPC is hard to google docs. How does one write an AND statement for it? e.g. for OR one does:
requirements = (CUDADeviceName == "Quadro RTX 6000") || (CUDADeviceName == "NVIDIA A40")
would:
requirements = (CUDADeviceName != "Tesla K40m") /\ (CUDADeviceName == "NVIDIA A40")
work? What I want is NOT tesla k40m and NOT A40. Anything else is fine.
Gives error:
(metalearning_gpu) miranda9~/diversity-for-predictive-success-of-meta-learning $ condor_submit job.sub
Submitting job(s)ERROR: Parse error in expression:
Requirements = ((CUDADeviceName != "Tesla K40m") /\ (CUDADeviceName != "NVIDIA A40")) && (TARGET.Arch == "X86_64") && (TARGET.OpSys == "LINUX") && (TARGET.Disk >= RequestDisk) && (TARGET.Memory >= RequestMemory) && (TARGET.Cpus >= RequestCpus) && (TARGET.gpus >= Requestgpus) && ((TARGET.FileSystemDomain == MY.FileSystemDomain) || (TARGET.HasFileTransfer))
For an AND/conjuction this seems to work:
requirements = (CUDADeviceName != "Tesla K40m") && (CUDADeviceName != "NVIDIA A40")
Yes, you want && for conjunction.
For a complete tutorial of the classad expression language, see the manual section at https://htcondor.readthedocs.io/en/latest/classads/index.html
Or, there's a YouTube tutorial about the expression language at
https://www.youtube.com/watch?v=Y8aHj8q56ik
I have a question, I have a subreport that prints many lines because it is in the detail band, for me this is fine, but I want to filter the rows based on parameters when I print the report, I used the option "print when" to set the Boolean condition but not it works, this works with only one parameter.
The condition is:
(!"N".equals($P{Chk_Amministratori})
|| ($F{field1} != $P{CheckDinamico1}
|| $F{field1} != $P{CheckDinamico2}
|| $F{field1} != $P{CheckDinamico3}
|| $F{field1} != $P{CheckDinamico4}
|| $F{field1} != $P{CheckDinamico5}
|| $F{field1} != $P{CheckDinamico6}
|| $F{field1} != $P{CheckDinamico7}
|| $F{field1} != $P{CheckDinamico8}
|| $F{field1} != $P{CheckDinamico10}) ? Boolean.TRUE : Boolean.FALSE
If I put a parameter it works, for example
$F{field1} != $P{CheckDinamico10} ? Boolean.TRUE : Boolean.FALSE
Can anyone help me?
The logic in your expressions is flawed. You have this
$F{field1} != $P{CheckDinamico1}
|| $F{field1} != $P{CheckDinamico2}
|| ...
Let's say CheckDinamico1 is 5 and CheckDinamico2 is 7. So your expressions is field1 != 5 OR field1 != 7 OR ..
This expression is true whatever the value of field1. If field1 is 3, it will be different from both 5 and 7, so the expression is true. If fiedl1 is 5, it will be different from 7, and because of OR the expression will also be true. And if field1 is 7, it will be different from 5 so again the expression is true.
Maybe you wanted AND instead of OR in the expression? Also, as Alex K noted, != might not always work so it's safer to use equals, and you can use primitive boolean expressions, you don't need Boolean. Therefore try something like this:
(!"N".equals($P{Chk_Amministratori})
|| (!$F{field1}.equals($P{CheckDinamico1})
&& !$F{field1}.equals($P{CheckDinamico2})
&& !$F{field1}.equals($P{CheckDinamico3})
&& !$F{field1}.equals($P{CheckDinamico4})
&& !$F{field1}.equals($P{CheckDinamico5})
&& !$F{field1}.equals($P{CheckDinamico6})
&& !$F{field1}.equals($P{CheckDinamico7})
&& !$F{field1}.equals($P{CheckDinamico8})
&& !$F{field1}.equals($P{CheckDinamico10}))
Could you please tell me what my mistake is on the following code:
if ((i>156-9 && i<156+9) && (j>406-9 && j<406+9)) || ((i>684-11 && i<684+11) && (j>274-11 && j<274+11)) || ((i>1066-15 && i<1066+15) && (j>67-15 && j<67+15)) || ((i>1559-15 && i<1559+15) && (j>867-15 && j<867+15)) || ((i>1082-18 && i<1082+18) && (j>740-18 && j<740+18))
plot(j, i, 'r+', 'MarkerSize', 7, 'LineWidth', 5);
end
I'd like to use an if statement which obeys to get in the expression if one of these conditions are fulfilled:
((i>156-9 && i<156+9) && (j>406-9 && j<406+9)) OR
((i>684-11 && i<684+11) && (j>274-11 && j<274+11)) OR
((i>1066-15 && i<1066+15) && (j>67-15 && j<67+15)) OR
((i>1559-15 && i<1559+15) && (j>867-15 && j<867+15)) OR
((i>1082-18 && i<1082+18) && (j>740-18 && j<740+18))
Thanks in advance...
Regards.
I have used your expression in the if as is and used this for this little piece of code.
clc; A=[];
for i=1:2000
for j=1:2000
if ((i>156-9 && i<156+9) && (j>406-9 && j<406+9)) || ((i>684-11 && i<684+11) && (j>274-11 && j<274+11)) || ((i>1066-15 && i<1066+15) && (j>67-15 && j<67+15)) || ((i>1559-15 && i<1559+15) && (j>867-15 && j<867+15)) || ((i>1082-18 && i<1082+18) && (j>740-18 && j<740+18))
A = [A, num2str(i),' ',num2str(j), char(10)];
end
end
end
display(A);
It works for me.
My last elseif statement does not execute even if the conditions are met:
Currency_Exchanage != 'Select...' and all other variables (ETF_Exchanage, Index_Exchanage and Stock_Exchanage) = 'Select...'
Here is the section of code that I am concerned about:
if (strcmp(ETF_Exchanage,'Select...') == 1) && (strcmp(Stock_Exchanage,'Select...') == 1) && (strcmp(Index_Exchanage,'Select...') == 1)...
(strcmp(Currency_Exchanage,'Select...') == 1)
if db == 1 && uni == 1
tickers = gnr_bloomberg; % Analsise Bloomberg natural resources
nrm=1;
elseif db == 1 && uni == 2
tickers = all_bloomberg; % Analsise Bloomberg all
nrm=1;
elseif db == 2 && uni == 1
tickers = gnr_yahoo; % Analsise Yahoo natural resources
nrm=1;
elseif db == 2 && uni == 2
tickers = all_yahoo; % Analsise Yahoo all
nrm=1;
end
else
%Yahoo inputs
if (strcmp(ETF_Exchanage,'Select...') == 0) && (strcmp(Stock_Exchanage,'Select...') == 1) && (strcmp(Index_Exchanage,'Select...') == 1)...
(strcmp(Currency_Exchanage,'Select...') == 1); %Choose exhanges from ETF
tickers = ETF_Yahoo(:,1);
Exchanges = ETF_Yahoo(:,2);
Exchange = ETF_Exchanage;
db=2; %Yahoo Selection
elseif (strcmp(Index_Exchanage,'Select...') == 0) && (strcmp(Stock_Exchanage,'Select...') == 1) && (strcmp(ETF_Exchanage,'Select...') == 1)...
(strcmp(Currency_Exchanage,'Select...') == 1); %Choose exhanges from Index
tickers = Index_Yahoo(:,1);
Exchanges = Index_Yahoo(:,2);
Exchange = Index_Exchanage;
db=2;
elseif (strcmp(Stock_Exchanage,'Select...') == 0) && (strcmp(ETF_Exchanage,'Select...') == 1) && (strcmp(Index_Exchanage,'Select...') == 1)...
(strcmp(Currency_Exchanage,'Select...') == 1); %Choose exhanges from Stock
tickers = Stock_Yahoo(:,1);
Exchanges = Stock_Yahoo(:,2);
Exchange = Stock_Exchanage;
db=2;
elseif (strcmp(Currency_Exchanage,'Select...') == 0) && (strcmp(Stock_Exchanage,'Select...') == 1) && (strcmp(Index_Exchanage,'Select...') == 1)...
(strcmp(ETF_Exchanage,'Select...') == 1); %Choose exhanges from Currency
tickers = Currency_Yahoo(:,1);
Exchanges = Currency_Yahoo(:,2);
Exchange = Currency_Exchanage;
db=2;
else
msg = 'Error occurred.\Only one Yahoo input menue must be used!';
error(msg)
end
end
Any Help would be much appropriated, I can't see where I'm going wrong here. I am using Matlab 2013a.
Put a breakpoint at the elseif statement in question and then check in the command window what your condition evaluates to.
If it does not evaluate like expected, check what the individual terms evaluate to.
It is important to actually test what the conditions evaluate to in matlab, rather than only visually comparing the string values.
Usually by that point you should get a rough idea what is wrong.
However in your case we can't do these steps for you because something is off. Your code condensed to the more reasonable minimal example
if 1 && 1 && 1...
1;
disp('I was here')
end
does not even execute in R2014a since the interpreter complains about '...' being an unexpected matlab expression.
if((([txtFldO1.text length] == 0 ) || ([txtFldO2.text length] == 0 ) ||
([txtFldO3.text length] == 0 ) || ([txtFldO4.text length] == 0 ) ||
([txtFldO5.text length] == 0 )) && (([txtFldR1.text length]== 0) ||
([txtFldR2.text length]== 0) || ([txtFldR3.text length]== 0) || ([txtFldR4.text length]== 0) || ([txtFldR5.text length]== 0)))
{
//alert
//return
}
This statement does not work. It does access all of the propeties. Could anyone tell me why?
I need to access one txtFldO and one txtFldR.
To access properties, try SELF
self.txtFld00.text.length
It should be like this.
if([txtFldO1.text length] == 0 || [txtFldO2.text length] == 0 || [txtFldO3.text length] == 0 || [txtFldO4.text length] == 0){
// Code here
}
You don't need to put parentheses before condition. Just put one parentheses like above example.
Hope this help.