C
C#4mo ago
Jexs

can someone help me read and understand this

I’m not good at understanding C sharp documentation…. Is the initialization and the condition considered a “statement or a block of statements”
No description
20 Replies
Jexs
JexsOP4mo ago
What is a statement
Angius
Angius4mo ago
A statement is basically... anything A method call, a variable assignment Another loop
Jexs
JexsOP4mo ago
Is the initialization and the condition considered a “statement or a block of statements”
Angius
Angius4mo ago
What do you mean by that? Variable initialization is a statement, yes An if is a statement as well Or do you mean initialization and condition in the for loop for example?
Evyr
Evyr4mo ago
Statements - C#
Learn about statements in C# programming. See a list of statement types, and view code examples and additional resources.
Jexs
JexsOP4mo ago
So you know how a for loop is set up like this… for (initialization, condition, iteration) what goes in the places of initialization, conditions, iteration are those called or considered statements @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius4mo ago
Statement, expression, statement In order
Jexs
JexsOP4mo ago
So what you just said lines up as such : initialization = statement , conditions = expression , iteration = statement @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius4mo ago
I'd say so Then again, I never really paid attention to what's called what It just doesn't really matter
Jexs
JexsOP4mo ago
Okay Ty zzzz you always pull through for me ! In the first sentence of what’s highlighted in the picture when they say “The iteration statements repeatedly execute a statement or a block of statements” are they talking about i++ in the example this: for (int i = 0; i < 10; i++)
Angius
Angius4mo ago
Iteration statement here being the loop as a whole
Jexs
JexsOP4mo ago
Oh
Angius
Angius4mo ago
So
for (var i = 0; i < 10; i++)
{

}
for (var i = 0; i < 10; i++)
{

}
This for statement will execute code within it's scope 10 times Or, in other words, as long as the condition expression evaluates to true
Jexs
JexsOP4mo ago
Give me one sec to re read over this A “block of statements” in this would also be considered Console.Writeline(“count up” + i) In this code For (int i =0; i<10; i++) { Console.Writeline(“count up” + i) } Also when they say “The iteration statements repeatedly execute a statement or a block of statements” they are talking about for loop, for each loop , do loop , and other loops sorry I’m just trying to really understand the first sentence
Evyr
Evyr4mo ago
In this particular case, this can be simplified to
for (int i = 0; i < 10; i++)
Console.WriteLine("count up" + i);
for (int i = 0; i < 10; i++)
Console.WriteLine("count up" + i);
Since you're iterating over a single statement. The curly braces allow you to iterate over a group/block of statements, and are required if you want to iterate over more than one at a time. that's what it means by "execute a statement or a block of statements"
Evyr
Evyr4mo ago
in this example the first, second and third loop are valid but the fourth is not, and will only iterate over the first Console.Write("i: "); statement. The error at the end is only shown because i doesn't exist outside of the for loops, but that Console.WriteLine would otherwise run a single time after the fourth loop finishes, not on every iteration.
No description
Jexs
JexsOP4mo ago
Give me some time to go over this thank you for your reply !
Angius
Angius4mo ago
Sure, a simple loop can have the braces removed, but... you really shouldn't
Absent_Reality
Absent_Reality4mo ago
I feel you on this. Every time I look through the docs, I feel like I need a full time English tutor, dictionary and an attorney just to understand them.
reflectronic
reflectronic4mo ago
well, the "language reference" on the documentation website is going to be reference material, not a tutorial
Want results from more Discord servers?
Add your server