473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

out of inner if?

Please advise?
I've never fully grasped scope/namespaces, but have been able to work around
earlier problems.
I now have a program flow situation in which I have *no choice* but to do
this this way.
Suppose I have something like;

var1=0.0;

main() {
/*do something sane*/
if (/*condition*/) {
var1=7.65347; //somenumber
}
//use var1's new value
}

How do I get a changed variable back out of an if statement's { } block?
I do math inside the if( ){ now, where before, the math was in the main()
function. I've now no choice: I'm skipping user entry IFF there's a file to
be read, with the same info in it that the user would have entered, so I
have to conditionalize many of the operations that otherwise were in the
main(){. )

I'm missing something simple I'm sure, and I _thought_ if I declared the
variable (initialized or not) outside of the main() function (hence global;
every loop should 'see' it no matter how nested), I could change it and it
would come back out changed, but I've had this same problem several times
now.
The 400+ line program compiles and runs, but my _info_ is gone 'cause it's
being calculated in an if( ){ instead of in the main(){ .

I'm frazzled. Please if there's a short/sweet way to spit the var back out
into the main(), let me know?
Thanks....
--
Peace
JB
jb@tetrahedraverse.com
Web: http://tetrahedraverse.com


Feb 16 '08 #1
3 1378
John Brawley wrote:
Please advise?
I've never fully grasped scope/namespaces, but have been able to work around
earlier problems.
I now have a program flow situation in which I have *no choice* but to do
this this way.
Suppose I have something like;

var1=0.0;

main() {
/*do something sane*/
if (/*condition*/) {
var1=7.65347; //somenumber
}
//use var1's new value
}

How do I get a changed variable back out of an if statement's { } block?
Declare the variable in main, but not in the if scope.

double var1;

if (/*condition*/) {
var1=7.65347; //somenumber
}

--
Ian Collins.
Feb 16 '08 #2
John Brawley wrote:
Please advise?
I've never fully grasped scope/namespaces, but have been able to work around
earlier problems.
I now have a program flow situation in which I have *no choice* but to do
this this way.
Suppose I have something like;

var1=0.0;

main() {
/*do something sane*/
if (/*condition*/) {
var1=7.65347; //somenumber
}
//use var1's new value
}

How do I get a changed variable back out of an if statement's { } block?
I do math inside the if( ){ now, where before, the math was in the main()
function. I've now no choice: I'm skipping user entry IFF there's a file to
be read, with the same info in it that the user would have entered, so I
have to conditionalize many of the operations that otherwise were in the
main(){. )

I'm missing something simple I'm sure, and I _thought_ if I declared the
variable (initialized or not) outside of the main() function (hence global;
every loop should 'see' it no matter how nested), I could change it and it
would come back out changed, but I've had this same problem several times
now.
The 400+ line program compiles and runs, but my _info_ is gone 'cause it's
being calculated in an if( ){ instead of in the main(){ .

I'm frazzled. Please if there's a short/sweet way to spit the var back out
into the main(), let me know?
Thanks....


It would help if you gave us a little complete example which produces
the output you do not like and tell us what output you expect.
Currently, it is not very clear what the problem is.

-Pavel
Feb 16 '08 #3
John Brawley wrote:
>>>
How do I get a changed variable back out of an if statement's { } block?
Declare the variable in main, but not in the if scope.

double var1;

if (/*condition*/) {
var1=7.65347; //somenumber
}
Please learn to trim and quote properly.
Nope; didn't do it....
Then you are doing something silly that you are not telling. Post a
minimal example that compiles and shows your problem.

--
Ian Collins.
Feb 16 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Murat Tasan | last post by:
hi, i am having a small problem with constructing an inner class. i am using an inner class (and not a static nested class) because the methods of the inner class need access to the enclosing...
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
8
by: olov.johansson | last post by:
Hi, given two nested functions: function outer() { function inner() { } } Is it determined by the ECMAScript standard that inner should be a property of outer, thus a...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
5
by: Martijn Mulder | last post by:
A construction like this: class Outer { class Inner:Outer { } } compiles without problem but does it introduce infinity?
1
by: mrstephengross | last post by:
I'm making progress on mixing templates with friends (sounds like a drinking game, huh?). Anyway, here's the situation. I've got an "Outer" class with a private "Inner" class (sub-class,...
9
by: Matthias Buelow | last post by:
Hi folks, I've got something like: class Outer { int f(); friend class Inner; class Inner { int g() {
3
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular...
2
by: MATTXtwo | last post by:
I have this store procedure to select data from table with join like this...SELECT tblPeribadi.Personel_No, tblPeribadi.Nama,tblCompany.Keterangan as Company_Code, tblPeribadi.Jawatan,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.