f



Difference between "while" and "if" (pretty basic)

Hello all,

I am new to programming in general. I am writing a script which finds solutions to a function of several variables. However, I am wanting my program to display a warning if  certain variables fall within barred ranges-- and these ranges are barred only if other variables fall within certain values.

Suppose I run a "for" loop with a = -100:5:100, and inside this loop, another for b = 0:1:10.  Suppose I want to display the warning when both a is greater than zero and b is between 2 and 6. (Those numbers are all made up for an example). Would it be appropriate to use while statements or if statements within the innermost loop? 

Something like 

while a>0
     if b>2 & b<6 
     disp('Warning: barred')

What is the difference between that and 

if a>0
     if b>2 & b<6 
     disp('Warning: barred')

Again, I understand this is basic programming stuff but I'm a newbie. Thanks for the help!
0
johnps (81)
6/27/2011 2:29:20 PM
comp.soft-sys.matlab 211264 articles. 26 followers. lunamoonmoon (257) is leader. Post Follow

8 Replies
896 Views

Similar Articles

[PageSpeed] 41

"John  Smith" <johnps@gmail.com> wrote in message <iua440$n0$1@newscl01ah.mathworks.com>...
> Hello all,
> 
> I am new to programming in general. I am writing a script which finds solutions to a function of several variables. However, I am wanting my program to display a warning if  certain variables fall within barred ranges-- and these ranges are barred only if other variables fall within certain values.
> 
> Suppose I run a "for" loop with a = -100:5:100, and inside this loop, another for b = 0:1:10.  Suppose I want to display the warning when both a is greater than zero and b is between 2 and 6. (Those numbers are all made up for an example). Would it be appropriate to use while statements or if statements within the innermost loop? 
> 
> Something like 
> 
> while a>0
>      if b>2 & b<6 
>      disp('Warning: barred')
> 
> What is the difference between that and 
> 
> if a>0
>      if b>2 & b<6 
>      disp('Warning: barred')
> 
> Again, I understand this is basic programming stuff but I'm a newbie. Thanks for the help!

Ok so I tested my own theoretical loops, and the "while" loops seems to have gone into some infinite loop while the "if" loop did exactly what I wanted. Can someone explain?
0
johnps (81)
6/27/2011 2:39:04 PM
On 6/27/2011 7:39 AM, John Smith wrote:
> "John  Smith"<johnps@gmail.com>  wrote in message<iua440$n0$1@newscl01ah.mathworks.com>...
>> Hello all,
>>
>> I am new to programming in general. I am writing a script which finds solutions to
>  a function of several variables. However, I am wanting my program to display a warning if
>  certain variables fall within barred ranges-- and these ranges are barred only if
>other variables fall within certain values.
>>
>> Suppose I run a "for" loop with a = -100:5:100, and inside this loop, another
>for b = 0:1:10.  Suppose I want to display the warning when both a is greater than
>  zero and b is between 2 and 6. (Those numbers are all made up for an example). Would
>it be appropriate to use while statements or if statements within the innermost loop?
>>
>> Something like
>>
>> while a>0
>>       if b>2&  b<6
>>       disp('Warning: barred')
>>
>> What is the difference between that and
>>
>> if a>0
>>       if b>2&  b<6
>>       disp('Warning: barred')
>>
>> Again, I understand this is basic programming stuff but I'm a newbie. Thanks for the help!
>
> Ok so I tested my own theoretical loops, and the "while" loops seems
>to have gone into some infinite loop while the "if" loop did exactly what I wanted. Can someone explain?

if you want to run the loops, then what you have is

LOOP over a values
      LOOP over b values
           ....
      END LOOP
END LOOP

Then to check for what you want, which is when 'a' is in some range
AND 'b' is in some range, you only need to do this check inside
the inner loop. Hence, one way might be:

---------------------
a=-100:5:100;
b=0:10;

for i=1:length(a)
     for j=1:length(b)
         if b(j)>2 && b(j)<6 && a(i)>0
            fprintf('warning, a=%f, b=%f\n',a(i),b(j));
         end
     end
end
-----------------------------
warning, a=5.000000, b=3.000000
warning, a=5.000000, b=4.000000
warning, a=5.000000, b=5.000000
warning, a=10.000000, b=3.000000
warning, a=10.000000, b=4.000000
warning, a=10.000000, b=5.000000
warning, a=15.000000, b=3.000000
warning, a=15.000000, b=4.000000
warning, a=15.000000, b=5.000000


--Nasser
0
Nasser
6/27/2011 2:51:41 PM
"Nasser M. Abbasi" <nma@12000.org> wrote in message <iua5ds$1kr$1@speranza.aioe.org>...
> On 6/27/2011 7:39 AM, John Smith wrote:
> > "John  Smith"<johnps@gmail.com>  wrote in message<iua440$n0$1@newscl01ah.mathworks.com>...
> >> Hello all,
> >>
> >> I am new to programming in general. I am writing a script which finds solutions to
> >  a function of several variables. However, I am wanting my program to display a warning if
> >  certain variables fall within barred ranges-- and these ranges are barred only if
> >other variables fall within certain values.
> >>
> >> Suppose I run a "for" loop with a = -100:5:100, and inside this loop, another
> >for b = 0:1:10.  Suppose I want to display the warning when both a is greater than
> >  zero and b is between 2 and 6. (Those numbers are all made up for an example). Would
> >it be appropriate to use while statements or if statements within the innermost loop?
> >>
> >> Something like
> >>
> >> while a>0
> >>       if b>2&  b<6
> >>       disp('Warning: barred')
> >>
> >> What is the difference between that and
> >>
> >> if a>0
> >>       if b>2&  b<6
> >>       disp('Warning: barred')
> >>
> >> Again, I understand this is basic programming stuff but I'm a newbie. Thanks for the help!
> >
> > Ok so I tested my own theoretical loops, and the "while" loops seems
> >to have gone into some infinite loop while the "if" loop did exactly what I wanted. Can someone explain?
> 
> if you want to run the loops, then what you have is
> 
> LOOP over a values
>       LOOP over b values
>            ....
>       END LOOP
> END LOOP
> 
> Then to check for what you want, which is when 'a' is in some range
> AND 'b' is in some range, you only need to do this check inside
> the inner loop. Hence, one way might be:
> 
> ---------------------
> a=-100:5:100;
> b=0:10;
> 
> for i=1:length(a)
>      for j=1:length(b)
>          if b(j)>2 && b(j)<6 && a(i)>0
>             fprintf('warning, a=%f, b=%f\n',a(i),b(j));
>          end
>      end
> end
> -----------------------------
> warning, a=5.000000, b=3.000000
> warning, a=5.000000, b=4.000000
> warning, a=5.000000, b=5.000000
> warning, a=10.000000, b=3.000000
> warning, a=10.000000, b=4.000000
> warning, a=10.000000, b=5.000000
> warning, a=15.000000, b=3.000000
> warning, a=15.000000, b=4.000000
> warning, a=15.000000, b=5.000000
> 
> 
> --Nasser

Thanks for the input. So what was it about "while" that made it go into an unending loop? I guess I don't quite understand what "while" does. 
0
johnps (81)
6/27/2011 3:10:23 PM
John Smith wrote:

....


> Thanks for the input. So what was it about "while" that made it go into 
> an unending loop? I guess I don't quite understand what "while" does.


It (while) is a logical looping construct, specifically.  IF is a 
logical branch structure (altho in Matlab unlike most other languages, 
it has an array implementation that one must understand to use it 
correctly).

If the logic test in a while statement is initially true and nothing is 
done inside the loop structure to make that condition become false, then 
you will have an infinite loop.

if otoh, is only evaluated once and some action branch taken.

doc while
doc if

Read "Getting Started" section on programming constructs.

--

0
non8502 (93)
6/27/2011 3:30:24 PM
dpb <non@non.net> wrote in message <4E08A210.20506@non.net>...
> John Smith wrote:
> 
> ...
> 
> 
> > Thanks for the input. So what was it about "while" that made it go into 
> > an unending loop? I guess I don't quite understand what "while" does.
> 
> 
> It (while) is a logical looping construct, specifically.  IF is a 
> logical branch structure (altho in Matlab unlike most other languages, 
> it has an array implementation that one must understand to use it 
> correctly).
> 
> If the logic test in a while statement is initially true and nothing is 
> done inside the loop structure to make that condition become false, then 
> you will have an infinite loop.
> 
> if otoh, is only evaluated once and some action branch taken.
> 
> doc while
> doc if
> 
> Read "Getting Started" section on programming constructs.
> 
> --
Alright, that helps! Thanks a lot. 
0
johnps (81)
6/27/2011 3:37:04 PM
"John  Smith" <johnps@gmail.com> wrote in message <iua6gv$96g$1@newscl01ah.mathworks.com>...
> "Nasser M. Abbasi" <nma@12000.org> wrote in message <iua5ds$1kr$1@speranza.aioe.org>...
> > On 6/27/2011 7:39 AM, John Smith wrote:
> > > "John  Smith"<johnps@gmail.com>  wrote in message<iua440$n0$1@newscl01ah.mathworks.com>...
> > >> Hello all,
> > >>
> > >> I am new to programming in general. I am writing a script which finds solutions to
> > >  a function of several variables. However, I am wanting my program to display a warning if
> > >  certain variables fall within barred ranges-- and these ranges are barred only if
> > >other variables fall within certain values.
> > >>
> > >> Suppose I run a "for" loop with a = -100:5:100, and inside this loop, another
> > >for b = 0:1:10.  Suppose I want to display the warning when both a is greater than
> > >  zero and b is between 2 and 6. (Those numbers are all made up for an example). Would
> > >it be appropriate to use while statements or if statements within the innermost loop?
> > >>
> > >> Something like
> > >>
> > >> while a>0
> > >>       if b>2&  b<6
> > >>       disp('Warning: barred')
> > >>
> > >> What is the difference between that and
> > >>
> > >> if a>0
> > >>       if b>2&  b<6
> > >>       disp('Warning: barred')
> > >>
> > >> Again, I understand this is basic programming stuff but I'm a newbie. Thanks for the help!
> > >
> > > Ok so I tested my own theoretical loops, and the "while" loops seems
> > >to have gone into some infinite loop while the "if" loop did exactly what I wanted. Can someone explain?
> > 
> > if you want to run the loops, then what you have is
> > 
> > LOOP over a values
> >       LOOP over b values
> >            ....
> >       END LOOP
> > END LOOP
> > 
> > Then to check for what you want, which is when 'a' is in some range
> > AND 'b' is in some range, you only need to do this check inside
> > the inner loop. Hence, one way might be:
> > 
> > ---------------------
> > a=-100:5:100;
> > b=0:10;
> > 
> > for i=1:length(a)
> >      for j=1:length(b)
> >          if b(j)>2 && b(j)<6 && a(i)>0
> >             fprintf('warning, a=%f, b=%f\n',a(i),b(j));
> >          end
> >      end
> > end
> > -----------------------------
> > warning, a=5.000000, b=3.000000
> > warning, a=5.000000, b=4.000000
> > warning, a=5.000000, b=5.000000
> > warning, a=10.000000, b=3.000000
> > warning, a=10.000000, b=4.000000
> > warning, a=10.000000, b=5.000000
> > warning, a=15.000000, b=3.000000
> > warning, a=15.000000, b=4.000000
> > warning, a=15.000000, b=5.000000
> > 
> > 
> > --Nasser
> 
> Thanks for the input. So what was it about "while" that made it go into an unending loop? I guess I don't quite understand what "while" does. 

% Lets go back to your original post (with a slight modification):

a = 10;
while a>0
   if b>2 & b<6 
      disp('Warning: barred')
   end
end

% Since a is never changed within the while loop, 
% then the while loop wiill be an "unending" loop.
% (Sometimes this is indeed desirable.  More later.)

% Now consider:

a = 10;
while a>0
   if b>2 & b<6 
      disp('Warning: barred')
   end
   a = a - 1;
end

% The tenth time through the while loop, it will terminate.
% The above is equivalent to:

for a = 10:-1:1
   if b>2 & b<6 
      disp('Warning: barred')
   end
end

% The "real" purpose of a while loop is when a varies 
% in some fashion you don't know about in advance.
% Consider:

a = 10;
while a>0
   if b>2 & b<6 
      disp('Warning: barred')
   end
   a = some_function_of(b);
end

% The loop will execute once, but then it will depend 
% on the returned value of a from some_function_of
% whether or not the wile loop continues.
0
someone3 (1980)
6/27/2011 3:40:20 PM

"John  Smith" <johnps@gmail.com> wrote in message 
news:iua4m8$2lm$1@newscl01ah.mathworks.com...
> "John  Smith" <johnps@gmail.com> wrote in message 
> <iua440$n0$1@newscl01ah.mathworks.com>...
>> Hello all,
>>
>> I am new to programming in general. I am writing a script which finds 
>> solutions to a function of several variables. However, I am wanting my 
>> program to display a warning if  certain variables fall within barred 
>> ranges-- and these ranges are barred only if other variables fall within 
>> certain values.
>>
>> Suppose I run a "for" loop with a = -100:5:100, and inside this loop, 
>> another for b = 0:1:10.  Suppose I want to display the warning when both 
>> a is greater than zero and b is between 2 and 6. (Those numbers are all 
>> made up for an example). Would it be appropriate to use while statements 
>> or if statements within the innermost loop? Something like while a>0
>>      if b>2 & b<6 disp('Warning: barred')
>>
>> What is the difference between that and if a>0
>>      if b>2 & b<6 disp('Warning: barred')
>>
>> Again, I understand this is basic programming stuff but I'm a newbie. 
>> Thanks for the help!
>
> Ok so I tested my own theoretical loops, and the "while" loops seems to 
> have gone into some infinite loop while the "if" loop did exactly what I 
> wanted. Can someone explain?

%%  ***** WHILE
a = 1; b = 0;
while a == 1
    b = b+1;
end

When the second line of this piece of code (the WHILE statement) executes, 
MATLAB checks if a is equal to 1. It is, so the WHILE loop body (line 3) 
executes and increases the value of b by 1. Then MATLAB reaches line 4 (the 
END statement) and returns to the second line of code.

When the second line of this piece of code (the WHILE statement) executes, 
MATLAB checks if a is equal to 1. It is, so the WHILE loop body (line 3) 
executes and increases the value of b by 1. Then MATLAB reaches line 4 (the 
END statement) and returns to the second line of code.

When the second line of this piece of code (the WHILE statement) executes, 
MATLAB checks if a is equal to 1. It is, so the WHILE loop body (line 3) 
executes and increases the value of b by 1. Then MATLAB reaches line 4 (the 
END statement) and returns to the second line of code.

.... wash, rinse, repeat.

a never changes inside the WHILE loop, so the WHILE condition is always 
going to be satisfied and the WHILE loop will always continue. To break the 
loop, you'd need to change the value of a to make the condition not be 
satisfied, use BREAK, or change the condition to depend on something that 
does change inside the loop.

a = 1; b = 0;
while a == 1
    b = b+1;
    if b == 5
        a = 2; % Condition unchanged, but will no longer be satisfied
    end
end

% or

a = 1; b = 0;
while a == 1
    b = b+1;
    if b == 5
        break % Explicitly broke out of the loop
    end
end

% or

a = 1; b = 0;
while a == 1 && b ~= 5 % Condition changed to depend on something varying 
inside the loop
    b = b+1;
end

%% **** IF
Compare this to the IF statement:

a = 1; b = 0;
if a == 1
    b = b+1;
end

When the second line of this piece of code (the IF statement) executes, 
MATLAB checks if (a == 1) is true. It is, so the IF statement body (line 3) 
executes and increases the value of b by 1. Then MATLAB reaches line 4 (the 
END statement) and continues on with the next statement (if any.) There's no 
looping involved in IF.

Since I'm guessing you're going to ask next about FOR, the other looping 
construct:

%% **** FOR
b = 0;
for a = 1:10
    b = b+1;
end

When the second line of code (the FOR statement) executes the first time, a 
takes on the first column from the vector 1:10, namely the scalar 1. Then 
the FOR loop body (line 3) executes and increases the value of b by 1. Then 
MATLAB reaches line 4 (the END statement) and checks if there are any more 
columns of the vector to process. Since there are, it returns to the second 
line of code.

When the second line of code (the FOR statement) executes the second time, a 
takes on the second column from the vector 1:10, namely the scalar 2. Then 
the FOR loop body (line 3) executes and increases the value of b by 1. Then 
MATLAB reaches line 4 (the END statement) and checks if there are any more 
columns of the vector to process. Since there are, it returns to the second 
line of code.

When the second line of code (the FOR statement) executes the third time, a 
takes on the third column from the vector 1:10, namely the scalar 3. Then 
the FOR loop body (line 3) executes and increases the value of b by 1. Then 
MATLAB reaches line 4 (the END statement) and checks if there are any more 
columns of the vector to process. Since there are, it returns to the second 
line of code.

.... wash, rinse, repeat until the tenth iteration.

When MATLAB reaches line 4 for the tenth time, it checks to see if there are 
any more columns of the expression  on line 2 for which it needs to execute 
the body. There aren't, so it continues on with the next statement after the 
END (if there are any, or exits the function if there aren't.)

-- 
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com 

0
slord (13689)
6/27/2011 3:55:08 PM
"Steven_Lord" <slord@mathworks.com> wrote in message <iua94s$hbd$1@newscl01ah.mathworks.com>...
> 
> 
> "John  Smith" <johnps@gmail.com> wrote in message 
> news:iua4m8$2lm$1@newscl01ah.mathworks.com...
> > "John  Smith" <johnps@gmail.com> wrote in message 
> > <iua440$n0$1@newscl01ah.mathworks.com>...
> >> Hello all,
> >>
> >> I am new to programming in general. I am writing a script which finds 
> >> solutions to a function of several variables. However, I am wanting my 
> >> program to display a warning if  certain variables fall within barred 
> >> ranges-- and these ranges are barred only if other variables fall within 
> >> certain values.
> >>
> >> Suppose I run a "for" loop with a = -100:5:100, and inside this loop, 
> >> another for b = 0:1:10.  Suppose I want to display the warning when both 
> >> a is greater than zero and b is between 2 and 6. (Those numbers are all 
> >> made up for an example). Would it be appropriate to use while statements 
> >> or if statements within the innermost loop? Something like while a>0
> >>      if b>2 & b<6 disp('Warning: barred')
> >>
> >> What is the difference between that and if a>0
> >>      if b>2 & b<6 disp('Warning: barred')
> >>
> >> Again, I understand this is basic programming stuff but I'm a newbie. 
> >> Thanks for the help!
> >
> > Ok so I tested my own theoretical loops, and the "while" loops seems to 
> > have gone into some infinite loop while the "if" loop did exactly what I 
> > wanted. Can someone explain?
> 
> %%  ***** WHILE
> a = 1; b = 0;
> while a == 1
>     b = b+1;
> end
> 
> When the second line of this piece of code (the WHILE statement) executes, 
> MATLAB checks if a is equal to 1. It is, so the WHILE loop body (line 3) 
> executes and increases the value of b by 1. Then MATLAB reaches line 4 (the 
> END statement) and returns to the second line of code.
> 
> When the second line of this piece of code (the WHILE statement) executes, 
> MATLAB checks if a is equal to 1. It is, so the WHILE loop body (line 3) 
> executes and increases the value of b by 1. Then MATLAB reaches line 4 (the 
> END statement) and returns to the second line of code.
> 
> When the second line of this piece of code (the WHILE statement) executes, 
> MATLAB checks if a is equal to 1. It is, so the WHILE loop body (line 3) 
> executes and increases the value of b by 1. Then MATLAB reaches line 4 (the 
> END statement) and returns to the second line of code.
> 
> ... wash, rinse, repeat.
> 
> a never changes inside the WHILE loop, so the WHILE condition is always 
> going to be satisfied and the WHILE loop will always continue. To break the 
> loop, you'd need to change the value of a to make the condition not be 
> satisfied, use BREAK, or change the condition to depend on something that 
> does change inside the loop.
> 
> a = 1; b = 0;
> while a == 1
>     b = b+1;
>     if b == 5
>         a = 2; % Condition unchanged, but will no longer be satisfied
>     end
> end
> 
> % or
> 
> a = 1; b = 0;
> while a == 1
>     b = b+1;
>     if b == 5
>         break % Explicitly broke out of the loop
>     end
> end
> 
> % or
> 
> a = 1; b = 0;
> while a == 1 && b ~= 5 % Condition changed to depend on something varying 
> inside the loop
>     b = b+1;
> end
> 
> %% **** IF
> Compare this to the IF statement:
> 
> a = 1; b = 0;
> if a == 1
>     b = b+1;
> end
> 
> When the second line of this piece of code (the IF statement) executes, 
> MATLAB checks if (a == 1) is true. It is, so the IF statement body (line 3) 
> executes and increases the value of b by 1. Then MATLAB reaches line 4 (the 
> END statement) and continues on with the next statement (if any.) There's no 
> looping involved in IF.
> 
> Since I'm guessing you're going to ask next about FOR, the other looping 
> construct:
> 
> %% **** FOR
> b = 0;
> for a = 1:10
>     b = b+1;
> end
> 
> When the second line of code (the FOR statement) executes the first time, a 
> takes on the first column from the vector 1:10, namely the scalar 1. Then 
> the FOR loop body (line 3) executes and increases the value of b by 1. Then 
> MATLAB reaches line 4 (the END statement) and checks if there are any more 
> columns of the vector to process. Since there are, it returns to the second 
> line of code.
> 
> When the second line of code (the FOR statement) executes the second time, a 
> takes on the second column from the vector 1:10, namely the scalar 2. Then 
> the FOR loop body (line 3) executes and increases the value of b by 1. Then 
> MATLAB reaches line 4 (the END statement) and checks if there are any more 
> columns of the vector to process. Since there are, it returns to the second 
> line of code.
> 
> When the second line of code (the FOR statement) executes the third time, a 
> takes on the third column from the vector 1:10, namely the scalar 3. Then 
> the FOR loop body (line 3) executes and increases the value of b by 1. Then 
> MATLAB reaches line 4 (the END statement) and checks if there are any more 
> columns of the vector to process. Since there are, it returns to the second 
> line of code.
> 
> ... wash, rinse, repeat until the tenth iteration.
> 
> When MATLAB reaches line 4 for the tenth time, it checks to see if there are 
> any more columns of the expression  on line 2 for which it needs to execute 
> the body. There aren't, so it continues on with the next statement after the 
> END (if there are any, or exits the function if there aren't.)
> 
> -- 
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on 
> http://www.mathworks.com 

Thanks Steve. That's the sort of line-by-line guidance I needed. Much appreciated, and very helpful! 
0
johnps (81)
6/27/2011 8:10:22 PM
Reply:

Similar Artilces:

""""""""""""""""""""""ADD ME""""""""""""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfo Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... We look forward to build a ve...

"""""""""ADD ME""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfoi Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... ...

Urgent Requirement in """""""""""""NEW YORK""""""""""""""""
Hello Partners, Please find the requirement below. Please send the updated resume along with rate and contact no. REQ#1: Title : Java Developer ( Rating Project) Duration : 6 months Rate : open Location : NY strong java, WebLogic 9.2, Web Services, Oracle REQ#2: Title : Java Developer Duration : 4 months Rate : open Location : NY Strong java, SQL REQ#3: Title : VB.Net Consultant Location : NY Duration : 4 months Rate : open Primarily looking at someone who has Excel, VB.net a...

"If then; if then;" and "If then; if;"
I have a raw data set which is a hierarchical file: H 321 s. main st P Mary E 21 F P william m 23 M P Susan K 3 F H 324 S. Main St I use the folowing code to read the data to creat one observation per detail(P) record including hearder record(H): data test; infile 'C:\Documents and Settings\retain.txt'; retain Address; input type $1. @; if type='H' then input @3 Address $12.; if type='P' then input @3 Name $10. @13 Age 3. @16 Gender $1.; run; but the output is not what I want: 1 321 s. main H 2 321 s. main P Mary E 21 F 3 321 s...

"out" and "in out"
Hi i found the following explaination: In Ada, "in" parameters are similar to C++ const parameters. They are effectively read-only within the scope of the called subprogram. Ada "in out" parameters have a reliable initial value (that passed in from the calling subprogram) and may be modified within the scope of the called procedure. Ada "out" parameters have no reliable initial value, but are expected to be assigned a value within the called procedure. What does "have no reliable initial value" mean when considering the "out" parameter? By c...

why "::", not "."
Why does the method of modules use a dot, and the constants a double colon? e.g. Math::PI and Math.cos -- Posted via http://www.ruby-forum.com/. On Oct 26, 2010, at 01:48 , Oleg Igor wrote: > Why does the method of modules use a dot, and the constants a double > colon? > e.g. > Math::PI and Math.cos For the same reason why inner-classes/modules use double colon, because = they're constants and that's how you look up via constant namespace. Math::PI and ActiveRecord::Base are the same type of lookup... it is = just that Base is a module and PI is a float....

"or" and "and"
Hi, I'm just getting to discover ruby, but I find it very nice programming language. I just still don't understand how the "or" and "and" in ruby... I was playing with ruby and for example made a def to print Stem and Leaf plot (for those who didn't have a statistics course or slept on it, e.g. http://cnx.org/content/m10157/latest/) Here is the Beta version of it: class Array def n ; self.size ; end def stem_and_leaf(st = 1) # if st != (2 or 5 or 10) then ; st = 1 ; end k = Hash.new(0) self.each {|x| k[x.to_f] += 1 } k = k.sort{|a, b| a[0].to_f <=&g...

"my" and "our"
Hi, while testing a program, I erroneously declared the same variable twice within a block, the first time with "my", the second time with "our": { my $fz = 'VTX_Link'; .... ( around 200 lines of code, all in the same block) our $fz = 'VTX_Linkset'; ... } So the initial contents of the $fz declared with "my" is lost, because "our" creates a lexical alias for the global $fz, thus overwriting the previous "my" declaration. It was my error, no question. But I wonder why Perl doesn't mention this - even with "use s...

"/a" is not "/a" ?
Hi everybody, while testing a module today I stumbled on something that I can work around but I don't quite understand. >>> a = "a" >>> b = "a" >>> a == b True >>> a is b True >>> c = "/a" >>> d = "/a" >>> c == d True # all good so far >>> c is d False # eeeeek! Why c and d point to two different objects with an identical string content rather than the same object? Manu Emanuele D'Arrigo wrote: >>>> c = "/a" >>>&...

about "++" and "--"
why this program snippet display "8,7,7,8,-7,-8" the program is: main() { int i=8; printf("%d\n%d\n%d\n%d\n%d\n%d\n",++i,--i,i++,i--,-i++,-i--); } > why this program snippet display "8,7,7,8,-7,-8" Ask your compiler-vendor because this result is IMHO implementation-defined. Check this out: http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.15 http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.16 Regards, Irina Marudina fxc123@gmail.com wrote: > why this program snippet display "8,7,7,8,-7,-8&q...

Urgent Requirement for """""""""""""""INFORMATICA DEVELOPER"""""""""""""
Hello Partners, How are you ? Please find the requirements below. Title: Database/ETL Developer Duration: 6 months Location: NY Exp: 7+ Locals preferred Database/ETL requirements (Mandatory) Candidate must have worked with financial instruments, preferably Mutual Funds but, Equities are also ok. PL/SQL - packages, Stored procs, Functions, Aggregate functions, Pipelined Functions Informatica 8.6 - especially complex mappings, complex maplets, complex workflows, transformations Oracle 10g/11g Unix/Linux shell scripting ...

Urgent need """""""""""INFORMATICA DEVELOPER"""""""""""""
Hello Partners, How are you ? Please find the requirements below. Title: Database/ETL Developer Duration: 6 months Location: NY Exp: 7+ Locals preferred Database/ETL requirements (Mandatory) Candidate must have worked with financial instruments, preferably Mutual Funds but, Equities are also ok. PL/SQL - packages, Stored procs, Functions, Aggregate functions, Pipelined Functions Informatica 8.6 - especially complex mappings, complex maplets, complex workflows, transformations Oracle 10g/11g Unix/Linux shell scripting Database/ETL requirements (Optional) Data warehousing experience Threading and job concepts in 10g/11g Cost based Optimizer concepts in 10g/11g Must : Experience with XML files and partitioning concepts in Oracle, Collections, Material Views Note : No phone calls please. : send Resumes to karthik@bhaninfo.com Thanks & Regards Karthik BhanInfo karthik@bhaninfo.com ...

different between the "::" and "."
Hello, class Myclass def Myclass.hi "hi" end def Myclass::hello "hello" end end what's the difference between Myclass.hi and Myclass::hello here? Thanks. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 11.12.2010 14:25, schrieb zuerrong: > Hello, > > class Myclass > def Myclass.hi > "hi" > end > def Myclass::hello > "hello" > end > end > > what's the difference between Myclass.hi and Myclass::hello here? ...

"In" "Out" and "Trash"
I just bought a new computer and I re-installed Eudora Light on my new computer. But when I open Eudora, the "In", "Out" and "Trash" links are not on the left side of the screen the way they were on my old computer. How can I get these links back on the left side of the screen? Thank you. On 25 Mar 2007 09:49:22 -0700, "abx" <abfunex@yahoo.com> wrote: >I just bought a new computer and I re-installed Eudora Light on my new >computer. But when I open Eudora, the "In", "Out" and "Trash" links >are ...

Does it need a ";" at the very after of "if" and "for"
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if statement? marsarden said: > write code like: > > int main(void) > { > int a=10; > if(a<20) > {} > } > > Compiler ok on dev-cpp . don't we have to add a ";" after if > statement? The syntax for 'if' is: if(expression) statement There is no semicolon after the ) but before the statement. The statement is either a normal statement (which can be empty), ending in a semicolon:- if(expr) ...

A problem about "[ ]" "( )" "="
I want to read several images saved in a director,and give them to I1,I2 ,I3....,using the following codes: filelist=dir(['c:\MATLAB701\work\...\*.jpg']); for i=1 :length(filelist) I=imread(fullfile('c:\MATLAB701\work\...',filelist(i).name)); end; but failed. Then I used I(i)=imread... ,still failed. How could I do? "John" <mailofww@126.com> wrote in message news:ef19e12.-1@webx.raydaftYaTP... >I want to read several images saved in a director,and give them to > I1,I2 ,I3....,using the following codes: > filelist=dir(['c:\MATLAB701\work\.....

Urgent JAVA Requirement in """"""NEW YORK"""""""""
Hello Partners, How are you ? Please find the requirement below. Location : NY Duration : 8 mnths Rate :Open Job description: Java/J2EE Web Service Developer =B7 (4+ years of application development experience in Java/J2EE and Web service technologies. =B7 Experience with spring & Hibernate. =B7 Experience with J2EE Application Server (preferably Web logic). =B7 Preferable Aqua logic DSP Experience =B7 Preferable Sonic ESB Composite Service experience Experience w...

puts "\\".gsub("\\", "\\\\")
Hello, I have a mini-ruby quiz. Guess what this line of code writes to the console, then try it for yourself: puts "\\".gsub("\\", "\\\\") Why is that so? Martin From: martinus [mailto:martin.ankerl@gmail.com]=20 # Hello, I have a mini-ruby quiz. Guess what this line of code writes to # the console, then try it for yourself: # puts "\\".gsub("\\", "\\\\") puts "\\".gsub("\\", "\\\\") \ #=3D> nil # Why is that so? faq. escaping the escape in sub/gsub. search the archives. maybe you want somethin...

Gary Sokolich """"""
"""""""""" http://www.manta.com/c/mmlq5dm/w-gary-sokolich W Gary Sokolich 801 Kings Road Newport Beach, CA 92663-5715 (949) 650-5379 http://www.tbpe.state.tx.us/da/da022808.htm TEXAS BOARD OF PROFESSIONAL ENGINEERS February 28, 2008 Board Meeting Disciplinary Actions W. Gary Sokolich , Newport Beach, California �V File B-29812 - It was alleged that Dr. Sokolich unlawfully offered or attempted to practice engineering in Texas (...) Dr. Sokolich chose to end the proceedings by signing a Consent Order that was accepted by ...

Question about "sprintf" "@" "do for"
Hello, this works: A1=3D1 A2=3D2 A3=3D3 i=3D1 vari=3Dsprintf("A%.f",i) print vari,"=3D",@vari i=3Di+1 vari=3Dsprintf("A%.f",i) print vari,"=3D",@vari i=3Di+1 vari=3Dsprintf("A%.f",i) print vari,"=3D",@vari do for [i=3D1:3]{ vari=3Dsprintf("A%.f",i) print vari } But I want to have "print vari,"=3D",@vari" in the loop. But it dosen't=20 work. Why can't I use "print vari,"=3D",@vari" in the loop? Is there a=20 solution for? J=C3=B6rg Jörg ...

what is the difference between "tsu", "su" and "sudo"?
Hi all I needed to ask a question about the Linux commands used for getting root access. The question is, what is the difference between "tsu", "su", and "sudo"? I am mainly interested about the "tsu" command regarding which there seems to be very little documentation. What is the benefit in using e.g. "tsu" rather than "su"? And are there other ones besides these 3? (If yes, any pointers to a website discussing all of them would be appreciated.) Thanks in advance, JJ <santa@temporaryinbox.com> writes...

How does a "script" differ from a "program" or "subroutine"?
Ok, stupid question for the day. I'm reading the interview with Steve Moret and he says: "Once a lot of scripts started going in we knew there was no way we could back out of using Python." I'm just getting into Python and am wondering if I'm missing something or this is just a semantic issue. Thanks. -Ted A subroutine is another name for "procedure", "function", or "method". They are made like this: def fu(): ... A program can contain any number of subroutines, along with classes, variables, etc. A script is just a program, but has ...

[News] The Difference Between "Favourite"/"Popular" and "Ubiqitous"/"Widespread"
Oh my Word ,----[ Quote ] | Microsoft Office Word is a candidate for the world's favourite | program, provided you accept BA's use of "favourite" as a synonym | for "ubiquitous" (me neither). `---- http://www.regdeveloper.co.uk/2006/10/04/word_users/ ...

"==" is NOT TRUE "==", WHY?
[CODE START] x=5; y=8; if (x + y + 1E-15 == 13) a = 3 else a = 8 end [CODE END] When x + y + 1E-15, the code above returns a = 8. When x + y + 1E-16, the code above returns a = 3. Why? Kindly advise. Thanks. "onemilimeter Chen" <onemm@example.com> wrote in message <g7adrj$5tr$1@fred.mathworks.com>... > [CODE START] > x=5; > y=8; > if (x + y + 1E-15 == 13) > a = 3 > else > a = 8 > end > [CODE END] > > When x + y + 1E-15, the code above returns a = 8. > When x + y + 1E-16, the code above returns a = 3. > > Why? ...

Web resources about - Difference between "while" and "if" (pretty basic) - comp.soft-sys.matlab

Resources last updated: 2/21/2016 8:16:33 PM