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