SlideShare a Scribd company logo
‫شرطی‬ ‫ساختارهای‬
‫حلقه‬ ‫و‬ ‫تکرار‬ ‫ساختارهای‬
 if ( Condition ) Statement
 if ( Condition ) Statement else Statement
 switch ( Condition )
 case Constant Expression: Statement
 …
 default: Statement
1. bool accept()
2. {
3. // Write question
4. cout << "Do you want to proceed (y or n)?n";
5.
6. char answer = 0;
7. cin >> answer; // Read answer
8.
9. if (answer == 'y')
10. return true;
11.
12. return false;
13. }
1. bool accept()
2. {
3. // Write question
4. cout << "Do you want to proceed (y or n)?n";
5.
6. char answer = 0;
7. cin >> answer; // Read answer
8.
9. if (answer == 'y')
10. return true;
11.
12. return false;
13. }
1. bool accept2()
2. {
3. // Write question
4. cout << "Do you want to proceed (y or n)?n";
5.
6. char answer = 0;
7. cin >> answer; // Read answer
8.
9. switch (answer)
10. {
11. case 'y':
12. return true;
13. case 'n':
14. return false;
15. default:
16. cout << "I'll take that for a no.n";
17. return false;
18. }
19. }
 while ( Condition ) Statement
 do Statement while ( Condition);
 for (Initialize; Condition; Expression)
Statement
1. bool accept3()
2. {
3. int tries = 1;
4. while (tries < 4)
5. {
6. // Write question
7. cout << "Do you want to proceed (y or n)?n";
8.
9. char answer = 0;
10. cin >> answer; // Read answer
11.
12. switch (answer)
13. {
14. case 'y':
15. return true;
16. case 'n':
17. return false;
18. default:
19. cout << "Sorry, I don't understand that.n";
20. ++tries; // Increment
21. }
22. }
23. cout << "I'll take that for a no.n";
24. return false;
25. }
1. bool accept4()
2. {
3. for (int tries = 1; tries<4; ++tries)
4. {
5. // Write question
6. cout << "Do you want to proceed (y or n)?n";
7.
8. char answer = 0;
9. cin >> answer; // Read answer
10.
11. switch (answer)
12. {
13. case 'y':
14. return true;
15. case 'n':
16. return false;
17. default:
18. cout << "Sorry, I don't understand that.n";
19. }
20. }
21. cout << "I'll take that for a no.n";
22. return false;
23. }
3. tests, loops

More Related Content

More from Vahid Heidari

12. standard library introduction
12. standard library introduction12. standard library introduction
12. standard library introduction
Vahid Heidari
 
11. template
11. template11. template
11. template
Vahid Heidari
 
10. copy and move
10. copy and move10. copy and move
10. copy and move
Vahid Heidari
 
9. class hierarchies
9. class hierarchies9. class hierarchies
9. class hierarchies
Vahid Heidari
 
8. abstract types
8. abstract types8. abstract types
8. abstract types
Vahid Heidari
 
7. abstraction mechanisms, containers
7. abstraction mechanisms, containers7. abstraction mechanisms, containers
7. abstraction mechanisms, containers
Vahid Heidari
 
6. separation, namespace, error
6. separation, namespace, error6. separation, namespace, error
6. separation, namespace, error
Vahid Heidari
 
5. struct, class, enum
5. struct, class, enum5. struct, class, enum
5. struct, class, enum
Vahid Heidari
 
4. pointers, arrays
4. pointers, arrays4. pointers, arrays
4. pointers, arrays
Vahid Heidari
 
2. types, vars, arith, consts
2. types, vars, arith, consts2. types, vars, arith, consts
2. types, vars, arith, consts
Vahid Heidari
 
1. preface, hello world
1. preface, hello world1. preface, hello world
1. preface, hello world
Vahid Heidari
 

More from Vahid Heidari (11)

12. standard library introduction
12. standard library introduction12. standard library introduction
12. standard library introduction
 
11. template
11. template11. template
11. template
 
10. copy and move
10. copy and move10. copy and move
10. copy and move
 
9. class hierarchies
9. class hierarchies9. class hierarchies
9. class hierarchies
 
8. abstract types
8. abstract types8. abstract types
8. abstract types
 
7. abstraction mechanisms, containers
7. abstraction mechanisms, containers7. abstraction mechanisms, containers
7. abstraction mechanisms, containers
 
6. separation, namespace, error
6. separation, namespace, error6. separation, namespace, error
6. separation, namespace, error
 
5. struct, class, enum
5. struct, class, enum5. struct, class, enum
5. struct, class, enum
 
4. pointers, arrays
4. pointers, arrays4. pointers, arrays
4. pointers, arrays
 
2. types, vars, arith, consts
2. types, vars, arith, consts2. types, vars, arith, consts
2. types, vars, arith, consts
 
1. preface, hello world
1. preface, hello world1. preface, hello world
1. preface, hello world
 

Recently uploaded

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
Ayan Halder
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 

Recently uploaded (20)

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 

3. tests, loops

  • 1.
  • 3.  if ( Condition ) Statement  if ( Condition ) Statement else Statement  switch ( Condition )  case Constant Expression: Statement  …  default: Statement
  • 4. 1. bool accept() 2. { 3. // Write question 4. cout << "Do you want to proceed (y or n)?n"; 5. 6. char answer = 0; 7. cin >> answer; // Read answer 8. 9. if (answer == 'y') 10. return true; 11. 12. return false; 13. }
  • 5. 1. bool accept() 2. { 3. // Write question 4. cout << "Do you want to proceed (y or n)?n"; 5. 6. char answer = 0; 7. cin >> answer; // Read answer 8. 9. if (answer == 'y') 10. return true; 11. 12. return false; 13. }
  • 6. 1. bool accept2() 2. { 3. // Write question 4. cout << "Do you want to proceed (y or n)?n"; 5. 6. char answer = 0; 7. cin >> answer; // Read answer 8. 9. switch (answer) 10. { 11. case 'y': 12. return true; 13. case 'n': 14. return false; 15. default: 16. cout << "I'll take that for a no.n"; 17. return false; 18. } 19. }
  • 7.  while ( Condition ) Statement  do Statement while ( Condition);  for (Initialize; Condition; Expression) Statement
  • 8. 1. bool accept3() 2. { 3. int tries = 1; 4. while (tries < 4) 5. { 6. // Write question 7. cout << "Do you want to proceed (y or n)?n"; 8. 9. char answer = 0; 10. cin >> answer; // Read answer 11. 12. switch (answer) 13. { 14. case 'y': 15. return true; 16. case 'n': 17. return false; 18. default: 19. cout << "Sorry, I don't understand that.n"; 20. ++tries; // Increment 21. } 22. } 23. cout << "I'll take that for a no.n"; 24. return false; 25. }
  • 9. 1. bool accept4() 2. { 3. for (int tries = 1; tries<4; ++tries) 4. { 5. // Write question 6. cout << "Do you want to proceed (y or n)?n"; 7. 8. char answer = 0; 9. cin >> answer; // Read answer 10. 11. switch (answer) 12. { 13. case 'y': 14. return true; 15. case 'n': 16. return false; 17. default: 18. cout << "Sorry, I don't understand that.n"; 19. } 20. } 21. cout << "I'll take that for a no.n"; 22. return false; 23. }

Editor's Notes

  1. در این ویدیو قصد دارم در مورد شرط ها و حلقه ها صحبت کنم و ساختار های حلقه رو بررسی می کنیم و برای هر کدوچند تا مثال می بینیم.
  2. شرط ها ساختار هایی هستند که اجازه میدند بر اساس شرایط که در برنامه پیش میاد تصمیم بگیریم که چه کاری صورت بگیره و چه دستوراتی اجرا بشن و چه دستوراتی اجرا نشن. 3 تا ساختار شرطی داریم که در این اسلاید می بیند. اولی ساختار if هست. بعد از کلمه if یک پرانتز باز و یک پرانتز بسته باید باشه که داخل اون شرطی که می خوایم چک کنیم رو می نویسیم. شرط داخل if همون عملگرهای منطقی هستند که در ویدیوی قبلی در موردشون صحبت کردیم. اگر که شرط if درست باشه دستورات بدنه ی if اجرامیشه و اگه درست نباشه از روی اون میپره و هیچ کدوم از دستورات if اجرا نمیشه. دومین ساختار If else هست که مشابه if هست ولی اگر شرط داخل If درست نباشه دستورات بدنه ی else رو اجرا می کنه ساختار بعدی switch case هست و به این صورت عمل می کنه که اگر شرط جلوی switch با مقدار هایی که جلوی caseهاست برابر باشه دستورات بدنه ی اون case اجرا میشه. یک مقدار اختیاری default هم داره که در صورتی که شرط جلوی switch با هیچ کدوم از caseها برابر نباشه دستورات default اجرا میشه. در انتهای هر case میتونید breakبذارید تا مشخص کنید که دستورات case تموم شده و از switch خارج بشیم در غیر این صورت؛ دستورات بعدی تا اولین break یا تا آخر اجرا میشن.
  3. یک مثال از if رو با هم ببینیم. در خط اول یک تابع داریم به نام accept که هیچ ورودی نمیگیره و type خروجی اون از نوع Boolean هست. بدنه تابع از خط 2 با یک آکولاد باز شروع میشه وبا یک آکولاد بسته در خط 13 تموم میشه. خط 3 یک comment نوشته شده. کامنت یعنی توضیحات. توضیحات با 2 تا اسلش شروع میشه وکامپایلر از جایی که توضیحات شروع میشه تا آخر خط رو نادیده میگیره. کامنت ها فقط برای اینه که یک توضیح یا نکته ای که مربوط به کدهای نوشته شده بدیم و تاثیری در اجرای برنامه ندارند.و یک کامنت دیگه هم در خط 7 میبینید. خط 4 رو با هم دیده بودیم از cout برای چاپ کردن یک پیغام روی صفحه قبلا استفاده کردیم. با اجرا شدن این خط یک پیغام روی صفحه نوشته میشه و سوال میکنه که آیا می خوایید جلوتر بریم یا نه. اگه کلید y رو بزنید به معنی yes هست و اگر کلید n رو بزنید یعنی no. خط 5 یک خط خالی هست و دستوری نوشته نشده. خط 6 یک متغییر declare شده به نام answer که type اون از نوع char هست یعنی میتونه یک حرف الفبا رو در خودش نگه داره و با مساوی صفر مقدار اولیه داده شده.
  4. خط 7 جدیده و قبلا ندیده بودیم. Cin مشابه cout هست ولی برعکس عمل میکنه یعنی یک مقداری رو از صفحه کلید میخونه و مقدارش رو به شما برمی گردونه. با دوتا علامت بزرگتر که بعد از cin می نویسیم، می تونیم یک مقداری رو بخونیم و بریزیم توی متغییری که جلوش اومده. cin یک کلید رو از صفحه کلید می خونه و مقدار اون رو توی متغییر answer که بالا declare کردیم میریزه. خط 9 از if استفاده کرده تا ببینه که چه کلیدی فشرده شده و بر اساس اون تصمیم میگیره که چکار کنه. داخل پرانتز باز و پرانتز بسته, شرطی که می خواییم چک کنیم رو می نویسیم و چک میکنیم که آیا متغییر answer که خوندیم؛ برابر حرف y هست یا نه. در صورتی که answer برابر حرف y باشه دستوراتی که زیر شرط if باشه اجرا میشه و در غیر این صورت هیچ دستوری رو اجرا نمی کنه. اگر حرف y وارد کرده باشیم دستور if در خط 10 اجرا میشه و مقدار true به عنوان مقدار خروجی تابع برگردونده میشه و از تابع خارج میشه و بقیه تابع رو اجرا نمی کنه. دقت کنید که حرف y رو داخل یک سینگل کوت گذاشتیم اگر y وارد نکرده باشیم شرط داخل if اشتباه خواهد شد و خط زیر if اجرا نمیشه و از روی شرط میپره میره بقیه تابع رو اجرا میکنه.در خط 12 هم مقدار false رو به عنوان خروجی بر گردونده.
  5. دراین مثال از ساختار تصمیم گیری switch case استفاده شده و چک می کنیم که اگر حرفی که وارد شده غیر از yes یا no بود یک پیغام مناسب هم چاپ می کنیم تا به کاربر اعلام کنیم که کلیدی که وارد کرده اشتباه بوده. این مثال مشابه مثال قبلیه ولی در خط 9 بجای if از switch استفاده شده. در شرط switch متغییر answer قرار داده شده. در صورتی که متغییر answer برابر یکی از مقدارهای جلوی یکی از caseها باشه دستورات اون case اجرا می شه. در صورتی که هیچ کدوم از مقادیر yes یا no نباشه دستورات default اجرا میشه که یک پیغام چاپ میکنه و مقدار false برگردونه.
  6. حلقه ها هم ساختار هایی هستند که با استفاده از اونا می تونیم یک سری دستورات را به صورت تکراری اجرا کنیم و معمولا درونشون شرط هایی وجود داره که بر اساس اون توقف یا ادامه ی انجام دستورات مشخص میشه. 3 تا ساختار حلقه داریم . While تا زمانی که شرط جلوش درست باشه دستورات رو اجرا میکنه. Do while اول یکبار دستورات رو اجرا میکنه و بعد شرط جلوی while رو چک میکنه. در صورتی که درست باشه دوباره میره ابتدای حلقه و دستورات رو یک بار دیگه اجرا میکنه. ساختار بعدی for هست که داخل پرانتز باز و بسته 3 قسمت وجود داره که با سمی کلون از هم جدا میشن. قسمت اول می شه یک متغییر برای شمارش تعداد تکرار رو تعریف و مقدار دهی اولیه کرد. در قسمت دوم معمولا یک شرط رو روی متغییر که در قسمت اول تعریف کردیم چک میکنیم که در صورتی که اشتباه بود حلقه دیگه تکرار نمیشه. در قسمت سوم هم روی متغییری که تعریف کردیم یه عملیات ریاضی انجام میشه مثلا یک واحد به اون اضافه میشه تا تعداد تکرار یکی اضافه بشه.
  7. یه مثال از while در این اسلاید میبینید. مثال قبلی رو طوری تغییر دادیم که در صورتی که کاربر 4 بار کلیدهای اشتباهی به غیر از yes و no زده باشه بهش هشدار میده و بعد از 4 بار از حلقه خارج میشه و یک پیغام میده و از تابع خارج میشه. در خط 3 یک متغییر به نام tries تعریف کریم و با 1 مقدار اولیه بهش دادیم. و داخل شرط while چک کردیم که اگه مقدارش کمتر از چهار بود دستورات حلقه رو اجرا کن. بدنه while از خط 5 شروع میشه و در خط 22 تموم میشه. داخل بدنه while یک تفاوت با مثال قبل داره و در بدنه ی default مقدار tries رو یک واحد افزایش دادیم. در صورتی که 4 بار کلیدهای غیر از yes و no بزنیم؛tries از 4 بیشتر میشه و شرط while اشتباه میشه در نتیجه از حلقه خارج میشیم و ادامه دستورات تابع اجرا میشه.
  8. در این مثال بجای while از حلقه for استفاده کردیم. هر حلقه ی while رو میشه با for باز نویسی کرد. بدنه ی for مثل مثال قبله. تفاوت در قسمت for هست. متغییر tries رو در داخل پرانتز تعریف می کنیم و یک سمی کلون میگذاریم بعد شرط خروج از حلقه رو می نویسیم و یک سمی کلون میذاریم و در آخر یک واحد به متغییر اضافه می کنیم. بقیه موارد دقیقا مثل مثال قبله یعنی اگر تعداد 4 بار حلقه انجام بشه مقدار tries از 4 بیشتر می شه و از حلقه خارج میشیم و ادامه دستورات بعد از حلقه اجرا میشن.
  9. در آخر جمع بندی بکنیم. در این ویدیو در مورد ساختار های شرط و ساختار های حلقه صحبت کردیم و چند مثال در مورد اونا باهم دیدیم. امید وارم مفید بوده باشه با تشکر