From 4edefe878b2f7c0bfcfdca6b103375e6c22b7b0f Mon Sep 17 00:00:00 2001 From: Ahmed AbdulKarim <54812827+AhmedAlDiab@users.noreply.github.com> Date: Mon, 24 Mar 2025 03:08:40 +0200 Subject: [PATCH] Update control-flow--statements@s5Gs4yF9TPh-psYmtPzks.md a concise description of various control statements in C++ I didn't know what to add other than this. --- ...-flow--statements@s5Gs4yF9TPh-psYmtPzks.md | 78 ++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/src/data/roadmaps/cpp/content/control-flow--statements@s5Gs4yF9TPh-psYmtPzks.md b/src/data/roadmaps/cpp/content/control-flow--statements@s5Gs4yF9TPh-psYmtPzks.md index 8b772289d..036e7a044 100644 --- a/src/data/roadmaps/cpp/content/control-flow--statements@s5Gs4yF9TPh-psYmtPzks.md +++ b/src/data/roadmaps/cpp/content/control-flow--statements@s5Gs4yF9TPh-psYmtPzks.md @@ -1 +1,77 @@ -# Control Flow & Statements \ No newline at end of file +# Control Statements in C++ + +Control statements direct the flow of your C++ program. Here's a concise overview: + +--- + +## If-Else Statement +Executes a code block if a condition is true; otherwise, it executes an alternative block. +```cpp +if (condition) { + // executed when condition is true +} else { + // executed when condition is false +} +``` + +--- + +## Switch Statement +Selects and executes a block of code based on the value of an expression. +```cpp +switch (expression) { + case value1: + // executed for value1 + break; + case value2: + // executed for value2 + break; + default: + // executed if no case matches +} +``` + +--- + +## Goto Statement +Unconditionally jumps to a labeled statement within the same function (use sparingly). +```cpp +goto label; +// ... +label: + // code to execute after jump +``` + +--- + +## For Loop +Repeats a block of code a specific number of times. +```cpp +for (initialization; condition; increment) { + // repeated code block +} +``` + +--- + +## While Loop +Executes a block of code repeatedly as long as a condition remains true. +```cpp +while (condition) { + // repeated code block +} +``` + +--- + +## Do-While Loop +Executes a block of code at least once, then repeats it while the condition remains true. +```cpp +do { + // code block executed at least once +} while (condition); +``` + +--- + +These statements form the foundation of controlling program flow in C++.