The document discusses different conditional and looping structures in C++ including if/else statements, switch statements, while loops, do-while loops, and for loops. It provides examples of a function called accept that uses these structures to prompt the user for input and return true if they enter 'y' or false otherwise, allowing for multiple tries.
This document does not contain any text to summarize. It appears to contain only special characters that do not convey meaningful information. In 3 sentences or less, a summary cannot be generated since there is no information present in the given text to summarize.
The document introduces several C++ standard library utilities including:
1) Chrono for measuring elapsed time between events in milliseconds.
2) Numeric limits for querying properties of fundamental types like the smallest positive float.
3) Iterator tags and overloading algorithms like sort based on iterator categories.
4) Type traits like is_arithmetic to check properties of types.
5) Pair and tuple for grouping multiple objects of different types.
The document discusses parallel programming concepts in C++ including threads, synchronization using mutexes, condition variables for producer-consumer problems, and futures/promises for asynchronous function calls. It provides examples of spawning threads to execute functions concurrently, protecting shared data with mutexes, notifying condition variables to signal events, and getting values from futures after asynchronous tasks have completed.
The document provides examples of using various C++ standard library containers and algorithms. It shows how to define a phone book using map and unordered_map containers and retrieve phone numbers by name. It also lists different container types and their characteristics, and provides examples of algorithms like sort, find, copy, and equal_range.
This document discusses containers like vectors and lists in C++. It provides examples of declaring and initializing vectors with different data types. Functions are demonstrated for printing, inserting, and searching elements in a vector. The document also contains examples of declaring and iterating through lists, and functions for inserting and removing elements from a list.
This document introduces C++ strings and I/O streams. It shows how to compose an email address from a name and domain, append to strings, extract substrings, and modify strings. Functions are defined to output integers and strings to stdout. The document also demonstrates reading user input, including integers and strings, from stdin. Finally, it defines a struct with name and number fields, overloads insertion and extraction operators for the struct, and uses these operators to read and write structs to I/O streams.
This document does not contain any text to summarize. It appears to contain only special characters that do not convey meaningful information. In 3 sentences or less, a summary cannot be generated since there is no information present in the given text to summarize.
The document introduces several C++ standard library utilities including:
1) Chrono for measuring elapsed time between events in milliseconds.
2) Numeric limits for querying properties of fundamental types like the smallest positive float.
3) Iterator tags and overloading algorithms like sort based on iterator categories.
4) Type traits like is_arithmetic to check properties of types.
5) Pair and tuple for grouping multiple objects of different types.
The document discusses parallel programming concepts in C++ including threads, synchronization using mutexes, condition variables for producer-consumer problems, and futures/promises for asynchronous function calls. It provides examples of spawning threads to execute functions concurrently, protecting shared data with mutexes, notifying condition variables to signal events, and getting values from futures after asynchronous tasks have completed.
The document provides examples of using various C++ standard library containers and algorithms. It shows how to define a phone book using map and unordered_map containers and retrieve phone numbers by name. It also lists different container types and their characteristics, and provides examples of algorithms like sort, find, copy, and equal_range.
This document discusses containers like vectors and lists in C++. It provides examples of declaring and initializing vectors with different data types. Functions are demonstrated for printing, inserting, and searching elements in a vector. The document also contains examples of declaring and iterating through lists, and functions for inserting and removing elements from a list.
This document introduces C++ strings and I/O streams. It shows how to compose an email address from a name and domain, append to strings, extract substrings, and modify strings. Functions are defined to output integers and strings to stdout. The document also demonstrates reading user input, including integers and strings, from stdin. Finally, it defines a struct with name and number fields, overloads insertion and extraction operators for the struct, and uses these operators to read and write structs to I/O streams.
The document introduces the C++ standard library and its main components. It discusses key elements like strings, I/O streams, containers and algorithms. It also mentions how the standard library provides runtime language support, the C standard library, and utilities to support common programming tasks like string handling, I/O, containers, algorithms, numerical computations, concurrency, metaprogramming and smart pointers.
The document describes C++ templates and how they can be used to define generic containers like Vector that work for different element types. It shows how to define a Vector class with a template parameter T for the element type. It also demonstrates how templates can be used to write algorithms that work on different container types by extracting the element type. Functions, classes, and type aliases can all be templated.
The document discusses copy and move semantics in C++. It provides examples of copy initialization, copy assignment, and copy constructors that make copies of objects. It then introduces move semantics using move constructors and move assignment that allow efficiently transferring resources from one object to another. The document shows how to implement move operations for a Vector class and demonstrates their use. It also shows how to delete copy and move operations to prevent objects from being copied or moved.
This document discusses abstract data types and containers in C++. It defines an abstract Container class with pure virtual functions for accessing elements and size. It then shows two classes, Vector_container and List_container, that implement the Container interface to allow a function to generically use different container types.
This document discusses C++ data types including fundamental types like int and double, user-defined types like structures and classes, and enumerations. It provides examples of defining a struct called Vector to represent an array, using Vector in a function, and converting Vector to a class. It also shows an example of an enumerator called Color and how to implement operator overloading for a prefix increment operator on an enum.
The document discusses arrays, pointers, references in C++. It defines arrays as collections of elements that can be accessed using indices starting from 0. It shows examples of declaring and initializing arrays, looping through arrays, copying arrays, printing array elements, and incrementing array elements. It also defines pointers as variables that store the address of another variable. It discusses pointer arithmetic and pointer to functions. It defines references as aliases to existing variables that must be initialized.
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Crescat
Crescat is industry-trusted event management software, built by event professionals for event professionals. Founded in 2017, we have three key products tailored for the live event industry.
Crescat Event for concert promoters and event agencies. Crescat Venue for music venues, conference centers, wedding venues, concert halls and more. And Crescat Festival for festivals, conferences and complex events.
With a wide range of popular features such as event scheduling, shift management, volunteer and crew coordination, artist booking and much more, Crescat is designed for customisation and ease-of-use.
Over 125,000 events have been planned in Crescat and with hundreds of customers of all shapes and sizes, from boutique event agencies through to international concert promoters, Crescat is rigged for success. What's more, we highly value feedback from our users and we are constantly improving our software with updates, new features and improvements.
If you plan events, run a venue or produce festivals and you're looking for ways to make your life easier, then we have a solution for you. Try our software for free or schedule a no-obligation demo with one of our product specialists today at crescat.io
SMS API Integration in Saudi Arabia| Best SMS API ServiceYara Milbes
Discover the benefits and implementation of SMS API integration in the UAE and Middle East. This comprehensive guide covers the importance of SMS messaging APIs, the advantages of bulk SMS APIs, and real-world case studies. Learn how CEQUENS, a leader in communication solutions, can help your business enhance customer engagement and streamline operations with innovative CPaaS, reliable SMS APIs, and omnichannel solutions, including WhatsApp Business. Perfect for businesses seeking to optimize their communication strategies in the digital age.
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
What is Master Data Management by PiLog Groupaymanquadri279
PiLog Group's Master Data Record Manager (MDRM) is a sophisticated enterprise solution designed to ensure data accuracy, consistency, and governance across various business functions. MDRM integrates advanced data management technologies to cleanse, classify, and standardize master data, thereby enhancing data quality and operational efficiency.
Zoom is a comprehensive platform designed to connect individuals and teams efficiently. With its user-friendly interface and powerful features, Zoom has become a go-to solution for virtual communication and collaboration. It offers a range of tools, including virtual meetings, team chat, VoIP phone systems, online whiteboards, and AI companions, to streamline workflows and enhance productivity.
WWDC 2024 Keynote Review: For CocoaCoders AustinPatrick Weigel
Overview of WWDC 2024 Keynote Address.
Covers: Apple Intelligence, iOS18, macOS Sequoia, iPadOS, watchOS, visionOS, and Apple TV+.
Understandable dialogue on Apple TV+
On-device app controlling AI.
Access to ChatGPT with a guest appearance by Chief Data Thief Sam Altman!
App Locking! iPhone Mirroring! And a Calculator!!
Artificia Intellicence and XPath Extension FunctionsOctavian Nadolu
The purpose of this presentation is to provide an overview of how you can use AI from XSLT, XQuery, Schematron, or XML Refactoring operations, the potential benefits of using AI, and some of the challenges we face.
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...XfilesPro
Wondering how X-Sign gained popularity in a quick time span? This eSign functionality of XfilesPro DocuPrime has many advancements to offer for Salesforce users. Explore them now!
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemPeter Muessig
Learn about the latest innovations in and around OpenUI5/SAPUI5: UI5 Tooling, UI5 linter, UI5 Web Components, Web Components Integration, UI5 2.x, UI5 GenAI.
Recording:
https://www.youtube.com/live/MSdGLG2zLy8?si=INxBHTqkwHhxV5Ta&t=0
The document introduces the C++ standard library and its main components. It discusses key elements like strings, I/O streams, containers and algorithms. It also mentions how the standard library provides runtime language support, the C standard library, and utilities to support common programming tasks like string handling, I/O, containers, algorithms, numerical computations, concurrency, metaprogramming and smart pointers.
The document describes C++ templates and how they can be used to define generic containers like Vector that work for different element types. It shows how to define a Vector class with a template parameter T for the element type. It also demonstrates how templates can be used to write algorithms that work on different container types by extracting the element type. Functions, classes, and type aliases can all be templated.
The document discusses copy and move semantics in C++. It provides examples of copy initialization, copy assignment, and copy constructors that make copies of objects. It then introduces move semantics using move constructors and move assignment that allow efficiently transferring resources from one object to another. The document shows how to implement move operations for a Vector class and demonstrates their use. It also shows how to delete copy and move operations to prevent objects from being copied or moved.
This document discusses abstract data types and containers in C++. It defines an abstract Container class with pure virtual functions for accessing elements and size. It then shows two classes, Vector_container and List_container, that implement the Container interface to allow a function to generically use different container types.
This document discusses C++ data types including fundamental types like int and double, user-defined types like structures and classes, and enumerations. It provides examples of defining a struct called Vector to represent an array, using Vector in a function, and converting Vector to a class. It also shows an example of an enumerator called Color and how to implement operator overloading for a prefix increment operator on an enum.
The document discusses arrays, pointers, references in C++. It defines arrays as collections of elements that can be accessed using indices starting from 0. It shows examples of declaring and initializing arrays, looping through arrays, copying arrays, printing array elements, and incrementing array elements. It also defines pointers as variables that store the address of another variable. It discusses pointer arithmetic and pointer to functions. It defines references as aliases to existing variables that must be initialized.
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Crescat
Crescat is industry-trusted event management software, built by event professionals for event professionals. Founded in 2017, we have three key products tailored for the live event industry.
Crescat Event for concert promoters and event agencies. Crescat Venue for music venues, conference centers, wedding venues, concert halls and more. And Crescat Festival for festivals, conferences and complex events.
With a wide range of popular features such as event scheduling, shift management, volunteer and crew coordination, artist booking and much more, Crescat is designed for customisation and ease-of-use.
Over 125,000 events have been planned in Crescat and with hundreds of customers of all shapes and sizes, from boutique event agencies through to international concert promoters, Crescat is rigged for success. What's more, we highly value feedback from our users and we are constantly improving our software with updates, new features and improvements.
If you plan events, run a venue or produce festivals and you're looking for ways to make your life easier, then we have a solution for you. Try our software for free or schedule a no-obligation demo with one of our product specialists today at crescat.io
SMS API Integration in Saudi Arabia| Best SMS API ServiceYara Milbes
Discover the benefits and implementation of SMS API integration in the UAE and Middle East. This comprehensive guide covers the importance of SMS messaging APIs, the advantages of bulk SMS APIs, and real-world case studies. Learn how CEQUENS, a leader in communication solutions, can help your business enhance customer engagement and streamline operations with innovative CPaaS, reliable SMS APIs, and omnichannel solutions, including WhatsApp Business. Perfect for businesses seeking to optimize their communication strategies in the digital age.
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
What is Master Data Management by PiLog Groupaymanquadri279
PiLog Group's Master Data Record Manager (MDRM) is a sophisticated enterprise solution designed to ensure data accuracy, consistency, and governance across various business functions. MDRM integrates advanced data management technologies to cleanse, classify, and standardize master data, thereby enhancing data quality and operational efficiency.
Zoom is a comprehensive platform designed to connect individuals and teams efficiently. With its user-friendly interface and powerful features, Zoom has become a go-to solution for virtual communication and collaboration. It offers a range of tools, including virtual meetings, team chat, VoIP phone systems, online whiteboards, and AI companions, to streamline workflows and enhance productivity.
WWDC 2024 Keynote Review: For CocoaCoders AustinPatrick Weigel
Overview of WWDC 2024 Keynote Address.
Covers: Apple Intelligence, iOS18, macOS Sequoia, iPadOS, watchOS, visionOS, and Apple TV+.
Understandable dialogue on Apple TV+
On-device app controlling AI.
Access to ChatGPT with a guest appearance by Chief Data Thief Sam Altman!
App Locking! iPhone Mirroring! And a Calculator!!
Artificia Intellicence and XPath Extension FunctionsOctavian Nadolu
The purpose of this presentation is to provide an overview of how you can use AI from XSLT, XQuery, Schematron, or XML Refactoring operations, the potential benefits of using AI, and some of the challenges we face.
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...XfilesPro
Wondering how X-Sign gained popularity in a quick time span? This eSign functionality of XfilesPro DocuPrime has many advancements to offer for Salesforce users. Explore them now!
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemPeter Muessig
Learn about the latest innovations in and around OpenUI5/SAPUI5: UI5 Tooling, UI5 linter, UI5 Web Components, Web Components Integration, UI5 2.x, UI5 GenAI.
Recording:
https://www.youtube.com/live/MSdGLG2zLy8?si=INxBHTqkwHhxV5Ta&t=0
SOCRadar's Aviation Industry Q1 Incident Report is out now!
The aviation industry has always been a prime target for cybercriminals due to its critical infrastructure and high stakes. In the first quarter of 2024, the sector faced an alarming surge in cybersecurity threats, revealing its vulnerabilities and the relentless sophistication of cyber attackers.
SOCRadar’s Aviation Industry, Quarterly Incident Report, provides an in-depth analysis of these threats, detected and examined through our extensive monitoring of hacker forums, Telegram channels, and dark web platforms.
Most important New features of Oracle 23c for DBAs and Developers. You can get more idea from my youtube channel video from https://youtu.be/XvL5WtaC20A
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesQuickdice ERP
Explore the seamless transition to e-invoicing with this comprehensive guide tailored for Saudi Arabian businesses. Navigate the process effortlessly with step-by-step instructions designed to streamline implementation and enhance efficiency.
Using Query Store in Azure PostgreSQL to Understand Query PerformanceGrant Fritchey
Microsoft has added an excellent new extension in PostgreSQL on their Azure Platform. This session, presented at Posette 2024, covers what Query Store is and the types of information you can get out of it.
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Łukasz Chruściel
No one wants their application to drag like a car stuck in the slow lane! Yet it’s all too common to encounter bumpy, pothole-filled solutions that slow the speed of any application. Symfony apps are not an exception.
In this talk, I will take you for a spin around the performance racetrack. We’ll explore common pitfalls - those hidden potholes on your application that can cause unexpected slowdowns. Learn how to spot these performance bumps early, and more importantly, how to navigate around them to keep your application running at top speed.
We will focus in particular on tuning your engine at the application level, making the right adjustments to ensure that your system responds like a well-oiled, high-performance race car.
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
در این ویدیو قصد دارم در مورد شرط ها و حلقه ها صحبت کنم و ساختار های حلقه رو بررسی می کنیم و برای هر کدوچند تا مثال می بینیم.
شرط ها ساختار هایی هستند که اجازه میدند بر اساس شرایط که در برنامه پیش میاد تصمیم بگیریم که چه کاری صورت بگیره و چه دستوراتی اجرا بشن و چه دستوراتی اجرا نشن.
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 یا تا آخر اجرا میشن.
یک مثال از if رو با هم ببینیم.
در خط اول یک تابع داریم به نام accept که هیچ ورودی نمیگیره و type خروجی اون از نوع Boolean هست.
بدنه تابع از خط 2 با یک آکولاد باز شروع میشه وبا یک آکولاد بسته در خط 13 تموم میشه.
خط 3 یک comment نوشته شده. کامنت یعنی توضیحات. توضیحات با 2 تا اسلش شروع میشه وکامپایلر از جایی که توضیحات شروع میشه تا آخر خط رو نادیده میگیره. کامنت ها فقط برای اینه که یک توضیح یا نکته ای که مربوط به کدهای نوشته شده بدیم و تاثیری در اجرای برنامه ندارند.و یک کامنت دیگه هم در خط 7 میبینید.
خط 4 رو با هم دیده بودیم از cout برای چاپ کردن یک پیغام روی صفحه قبلا استفاده کردیم. با اجرا شدن این خط یک پیغام روی صفحه نوشته میشه و سوال میکنه که آیا می خوایید جلوتر بریم یا نه. اگه کلید y رو بزنید به معنی yes هست و اگر کلید n رو بزنید یعنی no.
خط 5 یک خط خالی هست و دستوری نوشته نشده. خط 6 یک متغییر declare شده به نام answer که type اون از نوع char هست یعنی میتونه یک حرف الفبا رو در خودش نگه داره و با مساوی صفر مقدار اولیه داده شده.
خط 7 جدیده و قبلا ندیده بودیم. Cin مشابه cout هست ولی برعکس عمل میکنه یعنی یک مقداری رو از صفحه کلید میخونه و مقدارش رو به شما برمی گردونه. با دوتا علامت بزرگتر که بعد از cin می نویسیم، می تونیم یک مقداری رو بخونیم و بریزیم توی متغییری که جلوش اومده. cin یک کلید رو از صفحه کلید می خونه و مقدار اون رو توی متغییر answer که بالا declare کردیم میریزه.
خط 9 از if استفاده کرده تا ببینه که چه کلیدی فشرده شده و بر اساس اون تصمیم میگیره که چکار کنه. داخل پرانتز باز و پرانتز بسته, شرطی که می خواییم چک کنیم رو می نویسیم و چک میکنیم که آیا متغییر answer که خوندیم؛ برابر حرف y هست یا نه. در صورتی که answer برابر حرف y باشه دستوراتی که زیر شرط if باشه اجرا میشه و در غیر این صورت هیچ دستوری رو اجرا نمی کنه.
اگر حرف y وارد کرده باشیم دستور if در خط 10 اجرا میشه و مقدار true به عنوان مقدار خروجی تابع برگردونده میشه و از تابع خارج میشه و بقیه تابع رو اجرا نمی کنه.
دقت کنید که حرف y رو داخل یک سینگل کوت گذاشتیم
اگر y وارد نکرده باشیم شرط داخل if اشتباه خواهد شد و خط زیر if اجرا نمیشه و از روی شرط میپره میره بقیه تابع رو اجرا میکنه.در خط 12 هم مقدار false رو به عنوان خروجی بر گردونده.
دراین مثال از ساختار تصمیم گیری switch case استفاده شده و چک می کنیم که اگر حرفی که وارد شده غیر از yes یا no بود یک پیغام مناسب هم چاپ می کنیم تا به کاربر اعلام کنیم که کلیدی که وارد کرده اشتباه بوده.
این مثال مشابه مثال قبلیه ولی در خط 9 بجای if از switch استفاده شده.
در شرط switch متغییر answer قرار داده شده.
در صورتی که متغییر answer برابر یکی از مقدارهای جلوی یکی از caseها باشه دستورات اون case اجرا می شه.
در صورتی که هیچ کدوم از مقادیر yes یا no نباشه دستورات default اجرا میشه که یک پیغام چاپ میکنه و مقدار false برگردونه.
حلقه ها هم ساختار هایی هستند که با استفاده از اونا می تونیم یک سری دستورات را به صورت تکراری اجرا کنیم و معمولا درونشون شرط هایی وجود داره که بر اساس اون توقف یا ادامه ی انجام دستورات مشخص میشه.
3 تا ساختار حلقه داریم . While تا زمانی که شرط جلوش درست باشه دستورات رو اجرا میکنه.
Do while اول یکبار دستورات رو اجرا میکنه و بعد شرط جلوی while رو چک میکنه. در صورتی که درست باشه دوباره میره ابتدای حلقه و دستورات رو یک بار دیگه اجرا میکنه.
ساختار بعدی for هست که داخل پرانتز باز و بسته 3 قسمت وجود داره که با سمی کلون از هم جدا میشن. قسمت اول می شه یک متغییر برای شمارش تعداد تکرار رو تعریف و مقدار دهی اولیه کرد. در قسمت دوم معمولا یک شرط رو روی متغییر که در قسمت اول تعریف کردیم چک میکنیم که در صورتی که اشتباه بود حلقه دیگه تکرار نمیشه. در قسمت سوم هم روی متغییری که تعریف کردیم یه عملیات ریاضی انجام میشه مثلا یک واحد به اون اضافه میشه تا تعداد تکرار یکی اضافه بشه.
یه مثال از while در این اسلاید میبینید. مثال قبلی رو طوری تغییر دادیم که در صورتی که کاربر 4 بار کلیدهای اشتباهی به غیر از yes و no زده باشه بهش هشدار میده و بعد از 4 بار از حلقه خارج میشه و یک پیغام میده و از تابع خارج میشه.
در خط 3 یک متغییر به نام tries تعریف کریم و با 1 مقدار اولیه بهش دادیم.
و داخل شرط while چک کردیم که اگه مقدارش کمتر از چهار بود دستورات حلقه رو اجرا کن.
بدنه while از خط 5 شروع میشه و در خط 22 تموم میشه.
داخل بدنه while یک تفاوت با مثال قبل داره و در بدنه ی default مقدار tries رو یک واحد افزایش دادیم.
در صورتی که 4 بار کلیدهای غیر از yes و no بزنیم؛tries از 4 بیشتر میشه و شرط while اشتباه میشه در نتیجه از حلقه خارج میشیم و ادامه دستورات تابع اجرا میشه.
در این مثال بجای while از حلقه for استفاده کردیم. هر حلقه ی while رو میشه با for باز نویسی کرد.
بدنه ی for مثل مثال قبله.
تفاوت در قسمت for هست.
متغییر tries رو در داخل پرانتز تعریف می کنیم و یک سمی کلون میگذاریم
بعد شرط خروج از حلقه رو می نویسیم و یک سمی کلون میذاریم
و در آخر یک واحد به متغییر اضافه می کنیم. بقیه موارد دقیقا مثل مثال قبله یعنی اگر تعداد 4 بار حلقه انجام بشه مقدار tries از 4 بیشتر می شه و از حلقه خارج میشیم و ادامه دستورات بعد از حلقه اجرا میشن.
در آخر جمع بندی بکنیم. در این ویدیو در مورد ساختار های شرط و ساختار های حلقه صحبت کردیم و چند مثال در مورد اونا باهم دیدیم.
امید وارم مفید بوده باشه
با تشکر