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”
20 Replies
What is a statement
A statement is basically... anything
A method call, a variable assignment
Another loop
Is the initialization and the condition considered a “statement or a block of statements”
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?https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/statements describes different kinds of statements
Statements - C#
Learn about statements in C# programming. See a list of statement types, and view code examples and additional resources.
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
Statement, expression, statement
In order
So what you just said lines up as such : initialization = statement , conditions = expression , iteration = statement @ZZZZZZZZZZZZZZZZZZZZZZZZZ
I'd say so
Then again, I never really paid attention to what's called what
It just doesn't really matter
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++)
Iteration statement here being the loop as a whole
Oh
So
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
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
In this particular case, this can be simplified to
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"
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.Give me some time to go over this thank you for your reply !
Sure, a simple loop can have the braces removed, but... you really shouldn't
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.
well, the "language reference" on the documentation website is going to be reference material, not a tutorial