5
votes
2answers
119 views

Variable declaration in if clause

if(someCondition) int a=10;//Compilation Error else if(SomeOtherCondition){ int b=10;//no compilation Error } Why this happening.Why there is compilation error in first case. If i put braces then ...
1
vote
5answers
95 views

How can i declare a value in an if statement? (In java)

So this is what i have so far and i have no clue why the program is not responding the way i want it to. Keeps showing up that "avg2 might not have been initialized". Any ideas?? if (a < b ...
6
votes
4answers
287 views

double as true / false

Bjarne suggests using the condition in if's as scope restriction. In particular this example. if ( double d = fd() ) { // d in scope here... } I'm curios how to interpret the declaration in a ...
1
vote
1answer
232 views

Variable declaration in 'if' expression follow-up

This is a follow-up to C++, variable declaration in 'if' expression if( int x = 3 && true && 12 > 11 ) x = 1; The rules (so far as I can tell) are: can only have 1 variable ...
40
votes
5answers
7k views

C++, variable declaration in 'if' expression

What's going on here? if(int a = Func1()) { // Works. } if((int a = Func1())) { // Fails to compile. } if((int a = Func1()) && (int b = Func2())) ) { // Do stuff with a and ...
9
votes
1answer
144 views

php static in if statement

I have a construction like this in my config file: <?php if (true) { $nonstatic = 1; static $config = 1; } else { $nonstatic = 2; static $config = 2; } echo $nonstatic; echo ...