When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
54 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
You don't need a return statement for a void function unless you want to preemptively exit out of the function
Also it does not make sense to have a comma after a. You’d want a semicolon
Yeah the simple answer is just use braces and semicolons
if(a) cout << a, return;
You can't abuse the comma operator for this
Not much else to say
The continue one is definitely not possible
You could do:
T f(int a) {
if (a) { return std::cout << a, <some_value>; }
return <some_other_value>;
}
Return you can "cheese" yes
Just do if(a) { cout << a; }
Much better than the cursed thing you are doing with the comma
And for a void function you can just do:
void f(int a) {
if (a) std::cout << a;
}
No fun allowed 
Sure, but if I saw that pushed in a PR in my code base I’d get me mallet. 
The continue code of yours is just an endless loop
#cursed-code moment
That doesn't work.
The comma operator expects expressions as each sequence point.
contine is not an expression, nor is return
You can restructure your code, smth like:
void f(int a ){
while(a == 1){
std::cout << "A became 1!";
}
a = 1;
}
my god, then just remove them
#define NOT_A_CURLY_BRACE {
yes, but I want a continue
void f(int a ){
while(a == 1)
std::cout << "A became 1!";
a = 1;
}
dude
the code was dummy
the main thing I want is to be able to use continue
here I'll write a better one
that'd be great
void f(int a){
int cnt=0;
while(1){
if(cnt!=5) continue;
doSomeImportantWorkOmg();
break;
}
}
but now
say it has to be like
void f(int a){
int cnt=0, f=0;
while(1){
if(cnt!=5) f^=cnt, continue;
doSomeImportantWorkOmg(f);
break;
}
}
anyway I just want no curly braces and a continue 😭 too much to ask?
void f(int a){
int cnt=0;
while(cnt != 5)
f ^=cnt;
doSomeImportantWorkOmg();
}
ugh
If you want to forcefully use a continue, there's almost always a better way.
Not to mention that the continue doesn't work with the , operator
Because - as I said before - continue is not an expression (but a statement)
void solve(){
int n; cin>>n;
vector<int> a(n);
int f=-1, odd=-1;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++){
if(a[i]==1) f=i, continue;
// DON'T make this an else if and don't add a a[i]!=1
if(a[i]&1) odd=i;
}
}
I wouldn't know how to do that in a way that'd satisfy you, besides maybe this:
void solve(){
int n; cin>>n;
vector<int> a(n);
int f=-1, odd=-1;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++){
cin>>a[i];
if (a[i] & 1)
if (a[i] == 1) odd = i;
else f = i;
}
}
```or some dark `goto` magic, but I would really refrain from that.
But let me tell you, curly braces do not look ugly. Actually many people recommend to put them **even if you only have a oneliner**.
😔
If you want to impress them, then do some ternary magic:
for(int i=0;i<n;i++){
cin>>a[i];
f = !(a[i] - 1) ? i : f;
odd = (a[i] - 1) && (a[i] & 1) ? i : odd;
}
@full needle Has your question been resolved? If so, type !solved :)
Did you really just try to ping 32,610 people?
no just the people in this help channel man
thanks @hasty shale @magic mirage and @mellow frost for your help, I will close this now
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity