Hi guys,
what does exactly happen, when I have a extra pair of {} in the loop?
void loop()
{
A
{
B
}
}
void loop()
{
A
B
}
Is there any difference between above two codings?
Hi guys,
what does exactly happen, when I have a extra pair of {} in the loop?
void loop()
{
A
{
B
}
}
void loop()
{
A
B
}
Is there any difference between above two codings?
Delta_G:
Yes. You're defining a block as far as scope rules go. In the first one, any variables declared inside the B section are only available inside that section. They are local to the area between the { and}.
Coding support of the above proposition.
void setup()
{
}
void loop()
{
byte x = 0x23; //A
byte x = 0x45; //B ; not allowed ; re-declaration error
}
//---------------------------------
void setup()
{
}
void loop()
{
byte x = 0x23; //A
{
byte x = 0x45; //B this x is different from the above x; there is nothing such as re-declaration
}
}
@GolamMostafa - I do think that explaining things to beginners is not your strength. You often make things ten times more complex than they need to be.
Grumpy_Mike:
@GolamMostafa - I do think that explaining things to beginners is not your strength. You often make things ten times more complex than they need to be.
Delta_G:
Yes. You're defining a block as far as scope rules go. In the first one, any variables declared inside the B section are only available inside that section. They are local to the area between the { and}.
@Grumpy_Mike
I am glad to accept your criticism, but I am very much unhappy not see your any remark on @Delta_G's post (quoted above) where he (@Delta_G) has embedded tonnage of information.
GolamMostafa:
@Grumpy_Mike
I am glad to accept your criticism, but I am very much unhappy not see your any remark on @Delta_G's post (quoted above) where he (@Delta_G) has embedded tonnage of information.
I'm with Mike on this one.
AWOL:
I'm with Mike on this one.
For years, you have been with your biased sides as a Poster.
@Golam: I do not understand what you mean by the following comment.
//B this x is different from the above x; there is nothing such as re-declaration
Please explain what you mean by "nothing such as re-declaration".
Please explain to the OP why "this x is different from the above x". Perhaps it will be helpful for you to refer to Delta_G's comment in so doing.
The answers could be found by playing with the codes of Post#2.
Is the preventing re-declaration the only thing that happens with the extra of {} ? Hmm...