C# 05 Study Notes Compound and Iteration statements

C#

 

5.Compound and Iteration statements

5.1. Compound Assignment Operator

📌What is it?

📌Recommend

Don't😶Yes!😄
num = num + variable;num += variable;
num = num - variable;num -= variable;
num = num * variable;num *= variable;
num = num / variable;num /= variable;
num = num % variable;num %= variable;
num += 1;num++;

 

5.2. while loop

📌while loop in abstract

📌sentinel variable哨兵变量

The variable to end the while loop.

 

5.3. for loop

📌for loop in abstract

 

📌for loop in real

 

📌Multiple variable for loop⭐️

Output:

 

📌for loop can do more!⭐️⭐️⭐️

 

📌Variable in for loop is local variable

Output:

 

5.4. do statement

📌do in abstract

 

📌do in real

 

📌difference between do-while and while

In short, do-while has to do it at least once before iterating!

 

📌break and continue

Same with it in Python,

  • break - it jumps out the for/while loop directly
  • continue - it goes to the next iteration of for/while loop
Previous
Previous

Clean Coder # 02. Saying No

Next
Next

C# 24 Study Notes Concurrency by Asynchronous