if-else condition not working inside for loop in latex











up vote
0
down vote

favorite
1












I want to write if-else conditions inside the for-loop in my algorithm using LaTex. The problem that is if-else do not appear in the algorithm and then not working.



Here my LaTex code:



usepackage[pdftex]{graphicx}
%usepackage{float}
usepackage{amsmath}
%usepackage{algorithm}
usepackage{algorithmic}
%usepackage{algorithm2e}
usepackage[ruled,vlined,linesnumbered,noresetcount]{algorithm2e}
begin{document}

begin{algorithm}[H]
DontPrintSemicolon
SetAlgoLined
%KwResult{Write here the result}
SetKwInOut{Input}{Input}SetKwInOut{Output}{Output}
Input{input vector <$in_{vec}$>}
Output{output vector <$out_{vec}$>}
%BlankLine
Put threshold vector <$V_{thr}$>:~
($thr_{1}$,~$thr_{2}$,~$thr_{3}$,~......~,~$thr_{n}$);
For{$ith$ threshold in <$V_{thr}$> from i=1 to n}{
BlankLine
For{j=1 to length < $in_{vec}$>}{
IF{condition}
STATE $out_{vec}$ ~ leftarrow~ $[out_{vec}(i) + 1]$;
else
STATE $$out_{vec}$ ~ leftarrow~ $[out_{vec}(i) + 0]$;
}
text{$All data $leftarrow$ [Data_{1} + Data_{2}]$};
text{Label $All data $ with "1" and "0"};
}
text{Get $out_{vec}$ vector}
caption{Inutp output algorithm}
label{algorithm2}
end{algorithm}
end{document}


Output:



enter image description here



Why if and else conditions not working???










share|improve this question
























  • Welcome to TeX.SX! Your MWE does not have a documentclass command but, at a guess, your `IF` should be If and your else should be Else and you are missing EndIf.
    – Andrew
    yesterday












  • Oh, I tried but not working!!
    – Mohsen Ali
    yesterday















up vote
0
down vote

favorite
1












I want to write if-else conditions inside the for-loop in my algorithm using LaTex. The problem that is if-else do not appear in the algorithm and then not working.



Here my LaTex code:



usepackage[pdftex]{graphicx}
%usepackage{float}
usepackage{amsmath}
%usepackage{algorithm}
usepackage{algorithmic}
%usepackage{algorithm2e}
usepackage[ruled,vlined,linesnumbered,noresetcount]{algorithm2e}
begin{document}

begin{algorithm}[H]
DontPrintSemicolon
SetAlgoLined
%KwResult{Write here the result}
SetKwInOut{Input}{Input}SetKwInOut{Output}{Output}
Input{input vector <$in_{vec}$>}
Output{output vector <$out_{vec}$>}
%BlankLine
Put threshold vector <$V_{thr}$>:~
($thr_{1}$,~$thr_{2}$,~$thr_{3}$,~......~,~$thr_{n}$);
For{$ith$ threshold in <$V_{thr}$> from i=1 to n}{
BlankLine
For{j=1 to length < $in_{vec}$>}{
IF{condition}
STATE $out_{vec}$ ~ leftarrow~ $[out_{vec}(i) + 1]$;
else
STATE $$out_{vec}$ ~ leftarrow~ $[out_{vec}(i) + 0]$;
}
text{$All data $leftarrow$ [Data_{1} + Data_{2}]$};
text{Label $All data $ with "1" and "0"};
}
text{Get $out_{vec}$ vector}
caption{Inutp output algorithm}
label{algorithm2}
end{algorithm}
end{document}


Output:



enter image description here



Why if and else conditions not working???










share|improve this question
























  • Welcome to TeX.SX! Your MWE does not have a documentclass command but, at a guess, your `IF` should be If and your else should be Else and you are missing EndIf.
    – Andrew
    yesterday












  • Oh, I tried but not working!!
    – Mohsen Ali
    yesterday













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I want to write if-else conditions inside the for-loop in my algorithm using LaTex. The problem that is if-else do not appear in the algorithm and then not working.



Here my LaTex code:



usepackage[pdftex]{graphicx}
%usepackage{float}
usepackage{amsmath}
%usepackage{algorithm}
usepackage{algorithmic}
%usepackage{algorithm2e}
usepackage[ruled,vlined,linesnumbered,noresetcount]{algorithm2e}
begin{document}

begin{algorithm}[H]
DontPrintSemicolon
SetAlgoLined
%KwResult{Write here the result}
SetKwInOut{Input}{Input}SetKwInOut{Output}{Output}
Input{input vector <$in_{vec}$>}
Output{output vector <$out_{vec}$>}
%BlankLine
Put threshold vector <$V_{thr}$>:~
($thr_{1}$,~$thr_{2}$,~$thr_{3}$,~......~,~$thr_{n}$);
For{$ith$ threshold in <$V_{thr}$> from i=1 to n}{
BlankLine
For{j=1 to length < $in_{vec}$>}{
IF{condition}
STATE $out_{vec}$ ~ leftarrow~ $[out_{vec}(i) + 1]$;
else
STATE $$out_{vec}$ ~ leftarrow~ $[out_{vec}(i) + 0]$;
}
text{$All data $leftarrow$ [Data_{1} + Data_{2}]$};
text{Label $All data $ with "1" and "0"};
}
text{Get $out_{vec}$ vector}
caption{Inutp output algorithm}
label{algorithm2}
end{algorithm}
end{document}


Output:



enter image description here



Why if and else conditions not working???










share|improve this question















I want to write if-else conditions inside the for-loop in my algorithm using LaTex. The problem that is if-else do not appear in the algorithm and then not working.



Here my LaTex code:



usepackage[pdftex]{graphicx}
%usepackage{float}
usepackage{amsmath}
%usepackage{algorithm}
usepackage{algorithmic}
%usepackage{algorithm2e}
usepackage[ruled,vlined,linesnumbered,noresetcount]{algorithm2e}
begin{document}

begin{algorithm}[H]
DontPrintSemicolon
SetAlgoLined
%KwResult{Write here the result}
SetKwInOut{Input}{Input}SetKwInOut{Output}{Output}
Input{input vector <$in_{vec}$>}
Output{output vector <$out_{vec}$>}
%BlankLine
Put threshold vector <$V_{thr}$>:~
($thr_{1}$,~$thr_{2}$,~$thr_{3}$,~......~,~$thr_{n}$);
For{$ith$ threshold in <$V_{thr}$> from i=1 to n}{
BlankLine
For{j=1 to length < $in_{vec}$>}{
IF{condition}
STATE $out_{vec}$ ~ leftarrow~ $[out_{vec}(i) + 1]$;
else
STATE $$out_{vec}$ ~ leftarrow~ $[out_{vec}(i) + 0]$;
}
text{$All data $leftarrow$ [Data_{1} + Data_{2}]$};
text{Label $All data $ with "1" and "0"};
}
text{Get $out_{vec}$ vector}
caption{Inutp output algorithm}
label{algorithm2}
end{algorithm}
end{document}


Output:



enter image description here



Why if and else conditions not working???







algorithmic






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Andrew

29.3k34178




29.3k34178










asked yesterday









Mohsen Ali

263




263












  • Welcome to TeX.SX! Your MWE does not have a documentclass command but, at a guess, your `IF` should be If and your else should be Else and you are missing EndIf.
    – Andrew
    yesterday












  • Oh, I tried but not working!!
    – Mohsen Ali
    yesterday


















  • Welcome to TeX.SX! Your MWE does not have a documentclass command but, at a guess, your `IF` should be If and your else should be Else and you are missing EndIf.
    – Andrew
    yesterday












  • Oh, I tried but not working!!
    – Mohsen Ali
    yesterday
















Welcome to TeX.SX! Your MWE does not have a documentclass command but, at a guess, your `IF` should be If and your else should be Else and you are missing EndIf.
– Andrew
yesterday






Welcome to TeX.SX! Your MWE does not have a documentclass command but, at a guess, your `IF` should be If and your else should be Else and you are missing EndIf.
– Andrew
yesterday














Oh, I tried but not working!!
– Mohsen Ali
yesterday




Oh, I tried but not working!!
– Mohsen Ali
yesterday















active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460883%2fif-else-condition-not-working-inside-for-loop-in-latex%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460883%2fif-else-condition-not-working-inside-for-loop-in-latex%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt