At 9:53 AM +0530 8/30/10, Jatin Davey wrote:
 Hi All

I a newbie to perl. Reading through some of its basics on if constructs , while constructs and so i also found a the unless and until constructs.

let me take the if construct ,

basically it is like this :  if (<condition>) { .....}

now in the above construct if the condition evaluates to *true* only then does the body of the loop enclosed in { } is executed. SO what i understand is that the evaluation of truth in the condition is important for the code in the if block to execute. Please correct me if i am wrong in this regard.


You are correct, except where you call the statement(s) enclosed in braces {} a "loop". The statements are only executed one time for an 'if' statement, and that only if the condition is true. Your use of the term "block" to describe the statements enclosed by {} is correct.


Now coming to Unless and Until , The construct for this too is some thing like this:

unless (<condition>) {..........} and until (<condition>) {.....}

The unless construct above is correct. The 'until' construct is not. 'until' can only occur at the end of a block preceded by 'do' or at the end of a statement as a modifier.

do {
      ...
} until( condition );

or

die unless(condition);



Now i wanted to know when does the body of these constructs would execute , Is it when the condition evaluates to true or false ?


'unless(condition){...}' is the same as 'if( ! condition ) {...}'

The block is executed if the condition evaluates to false.

See the built-in Perl documentation available from a command-line as 'perldoc perlsyn'.


--
Jim Gibson
j...@gibson.org

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to