1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
ok. I suspected as much, but as I said, fork() is a distant memory to me.
so, c++, then:
if(condition)
{
//if condition is true, these happen
}
else
{
//these happen if condition above is false
}
and it is THAT SIMPLE.
you can chain if-statements in the expected ways, an if can be
inside another if, inside an else, or chain the elses
(else-if, but else-if isnt a single statment in c++, its just a chain
of else statement that consists entirely of an if-statement block. )
so
if(condition)
{
;
}
else if(other condition)
is really this to c++:
if(condition)
{
;
}
else
{
if(other condition)
{
;
}
}
| |
even though many coders write else if on the same line as one statement, it is not, it is two blocks of code written in a way that tells the reader what is going on. Its really just a shortcut to the above explicit blocks.
It is confusing as crap to c++ coders to move to py which uses whitespace to denote blocks of related code. C++ uses {} and implicit {} to denote code blocks. The implicit ones are ALWAYS one single statement (which can, itself, trigger a block).
if(foo)
cout << foo; //implicit block
cout << bar; //this is NOT inside that IF statement block. This statement always happens.
a side effect of using {} blocks in c++ coupled with another feature of the language (the compiler ignores most whitespace) is what allows the else if on a single line to work in c++.
last one:
if(foo)
while(bar)
{
code; //this is inside the while which is inside the if via and implicit {} block.
}
I personally try to put {} even on single statements so there are never implicit {} code blocks. Its a self defense anti-bug tactic. The else if shortcut is the only place I do not.
syntax aside it works pretty much like py. The problem here was threading and splitting the process, not the conditional blocks.