Re: for loops without braces?

  • From: "qubit" <lauraeaves@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 18 Nov 2010 22:03:05 -0600

correct

----- Original Message ----- 
From: "Alex Hall" <mehgcap@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Thursday, November 18, 2010 9:13 PM
Subject: Re: for loops without braces?


Thanks for the quick responses. So, would the following be correct?

for(i=0;i<10;i++)
print(i-1);
print(i+1);
if(i%2==0){
print(i);
}

or would only the first statement after the for, the print(i-1), be
executed and then the loop exited?

On 11/18/10, qubit <lauraeaves@xxxxxxxxx> wrote:
> easily -- when the compiler reaches the end of the statement following 
> the )
> of the for loop header.
> Here the statement is the if statement, which could be huge and even 
> contain
> an else clause, but according to C++ syntax, the compiler has to parse the
> complete statement before closing the for loop.
> --le
> ----- Original Message -----
> From: "Alex Hall" <mehgcap@xxxxxxxxx>
> To: <programmingblind@xxxxxxxxxxxxx>
> Sent: Thursday, November 18, 2010 8:09 PM
> Subject: for loops without braces?
>
>
> Hi all,
> I am desperately trying to understand Prim's algorithm. I have found
> it in pseudocode and C code, but in both examples they use for loops
> without braces, so it might be:
> for(i=0; i<4; i++)
> if(i%2==0){
> print(i);
> }
>
> Obviously this is understandable, but when you mix it into other code
> it becomes much harder to tell what is going on. First, how can one do
> this syntactically and have it be correct? Second, what is the rule to
> figure out where the loop ends if it is not in braces? The C compiler
> must have a way...
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: